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 "chrome/browser/signin/signin_manager_factory.h"
15 #include "components/signin/core/browser/signin_manager_base.h"
17 // This class provides access to a list of email addresses for all profiles
18 // connected to a Google account, from the IO thread. The main purpose of
19 // this is to be a member of the ProfileIOData structure to allow access to
20 // the list of email addresses, and is used by the one-click sign in code to
21 // know which Google accounts are already in use.
23 // Instance of this class are created and initialized on the UI
24 // thread as part of the creation of ProfileIOData, and destroyed along with
26 class SigninNamesOnIOThread
: public SigninManagerBase::Observer
,
27 public SigninManagerFactory::Observer
{
29 typedef std::set
<base::string16
> EmailSet
;
31 // Objects should only be created on UI thread.
32 SigninNamesOnIOThread();
33 ~SigninNamesOnIOThread() override
;
35 // Gets the set of email addresses of connected profiles. This method should
36 // only be called on the IO thread.
37 const EmailSet
& GetEmails() const;
39 // Releases all resource held by object. Once released, GetEmails() no
41 void ReleaseResourcesOnUIThread();
44 // SigninManagerBase::Observer:
45 void GoogleSigninSucceeded(const std::string
& account_id
,
46 const std::string
& username
,
47 const std::string
& password
) override
;
48 void GoogleSignedOut(const std::string
& account_id
,
49 const std::string
& username
) override
;
51 // SigninManagerFactory::Observer:
52 void SigninManagerCreated(SigninManagerBase
* manager
) override
;
53 void SigninManagerShutdown(SigninManagerBase
* manager
) override
;
55 // Checks whether the current thread is the IO thread.
56 void CheckOnIOThread() const;
58 // Checks whether the current thread is the UI thread.
59 void CheckOnUIThread() const;
61 // Posts a task to the I/O thread to add or remove the email address from
63 void PostTaskToIOThread(bool add
, const base::string16
& email
);
65 // Updates the email set on the I/O thread. Protected for testing.
66 void UpdateOnIOThread(bool add
, const base::string16
& email
);
70 // The set of SigninManagerBase instances that this instance is currently
71 // observing. Can only be accessed on the UI thread.
72 std::set
<SigninManagerBase
*> observed_managers_
;
73 bool resources_released_
;
75 DISALLOW_COPY_AND_ASSIGN(SigninNamesOnIOThread
);
78 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_NAMES_IO_THREAD_H_