20902ba681c971135ffabfd3cc9f6c9f2f8e47e5
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / signin_names_io_thread.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_NAMES_IO_THREAD_H_
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_NAMES_IO_THREAD_H_
7
8 #include <set>
9
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16
17 namespace content {
18 class NotificationDetails;
19 class NotificationSource;
20 }
21
22
23 // This class provides access to a list of email addresses for all profiles
24 // connected to a Google account, from the IO thread.  The main purpose of
25 // this is to be a member of the ProfileIOData structure to allow access to
26 // the list of email addresses, and is used by the one-click sign in code to
27 // know which Google accounts are already in use.
28 //
29 // Instance of this class are created and initialized on the UI
30 // thread as part of the creation of ProfileIOData, and destroyed along with
31 // ProfileIOData.
32 class SigninNamesOnIOThread : public content::NotificationObserver {
33  public:
34   typedef std::set<base::string16> EmailSet;
35
36   // Objects should only be created on UI thread.
37   SigninNamesOnIOThread();
38   virtual ~SigninNamesOnIOThread();
39
40   // Gets the set of email addresses of connected profiles.  This method should
41   // only be called on the IO thread.
42   const EmailSet& GetEmails() const;
43
44   // Releases all resource held by object. Once released, GetEmails() no
45   // longer works.
46   void ReleaseResourcesOnUIThread();
47
48  private:
49   // content::NotificationObserver
50   virtual void Observe(int type,
51                         const content::NotificationSource& source,
52                         const content::NotificationDetails& details) OVERRIDE;
53
54   // Checks whether the current thread is the IO thread.
55   void CheckOnIOThread() const;
56
57   // Checks whether the current thread is the UI thread.
58   void CheckOnUIThread() const;
59
60   // Posts a task to the I/O thread to add or remove the email address from
61   // the set.
62   void PostTaskToIOThread(int type, const base::string16& email);
63
64   // Updates the email set on the I/O thread.  Protected for testing.
65   void UpdateOnIOThread(int type, const base::string16& email);
66
67   scoped_ptr<content::NotificationRegistrar> registrar_;
68   EmailSet emails_;
69
70   DISALLOW_COPY_AND_ASSIGN(SigninNamesOnIOThread);
71 };
72
73 #endif  // CHROME_BROWSER_SIGNIN_SIGNIN_NAMES_IO_THREAD_H_