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.
5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_NAMES_IO_THREAD_H_
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_NAMES_IO_THREAD_H_
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"
18 class NotificationDetails;
19 class NotificationSource;
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.
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
32 class SigninNamesOnIOThread : public content::NotificationObserver {
34 typedef std::set<base::string16> EmailSet;
36 // Objects should only be created on UI thread.
37 SigninNamesOnIOThread();
38 virtual ~SigninNamesOnIOThread();
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;
44 // Releases all resource held by object. Once released, GetEmails() no
46 void ReleaseResourcesOnUIThread();
49 // content::NotificationObserver
50 virtual void Observe(int type,
51 const content::NotificationSource& source,
52 const content::NotificationDetails& details) OVERRIDE;
54 // Checks whether the current thread is the IO thread.
55 void CheckOnIOThread() const;
57 // Checks whether the current thread is the UI thread.
58 void CheckOnUIThread() const;
60 // Posts a task to the I/O thread to add or remove the email address from
62 void PostTaskToIOThread(int type, const base::string16& email);
64 // Updates the email set on the I/O thread. Protected for testing.
65 void UpdateOnIOThread(int type, const base::string16& email);
67 scoped_ptr<content::NotificationRegistrar> registrar_;
70 DISALLOW_COPY_AND_ASSIGN(SigninNamesOnIOThread);
73 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_NAMES_IO_THREAD_H_