Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: components/gcm_driver/gcm_driver_desktop.h

Issue 330733002: Move IdentityProvider usage from GCMDriverDesktop to GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix after sync Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_
6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ 6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "components/gcm_driver/gcm_client.h" 17 #include "components/gcm_driver/gcm_client.h"
18 #include "components/gcm_driver/gcm_driver.h" 18 #include "components/gcm_driver/gcm_driver.h"
19 #include "google_apis/gaia/identity_provider.h"
20 19
21 namespace base { 20 namespace base {
22 class FilePath; 21 class FilePath;
23 class SequencedTaskRunner; 22 class SequencedTaskRunner;
24 } 23 }
25 24
26 namespace extensions { 25 namespace extensions {
27 class ExtensionGCMAppHandlerTest; 26 class ExtensionGCMAppHandlerTest;
28 } 27 }
29 28
30 namespace net { 29 namespace net {
31 class URLRequestContextGetter; 30 class URLRequestContextGetter;
32 } 31 }
33 32
34 namespace gcm { 33 namespace gcm {
35 34
36 class GCMAppHandler; 35 class GCMAppHandler;
37 class GCMClientFactory; 36 class GCMClientFactory;
38 37
39 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. 38 // GCMDriver implementation for desktop and Chrome OS, using GCMClient.
40 class GCMDriverDesktop : public GCMDriver, public IdentityProvider::Observer { 39 class GCMDriverDesktop : public GCMDriver {
41 public: 40 public:
42 GCMDriverDesktop( 41 GCMDriverDesktop(
43 scoped_ptr<GCMClientFactory> gcm_client_factory, 42 scoped_ptr<GCMClientFactory> gcm_client_factory,
44 scoped_ptr<IdentityProvider> identity_provider,
45 const GCMClient::ChromeBuildInfo& chrome_build_info, 43 const GCMClient::ChromeBuildInfo& chrome_build_info,
46 const base::FilePath& store_path, 44 const base::FilePath& store_path,
47 const scoped_refptr<net::URLRequestContextGetter>& request_context, 45 const scoped_refptr<net::URLRequestContextGetter>& request_context,
48 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 46 const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
49 const scoped_refptr<base::SequencedTaskRunner>& io_thread, 47 const scoped_refptr<base::SequencedTaskRunner>& io_thread,
50 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); 48 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
51 virtual ~GCMDriverDesktop(); 49 virtual ~GCMDriverDesktop();
52 50
53 // IdentityProvider::Observer implementation:
54 virtual void OnActiveAccountLogin() OVERRIDE;
55 virtual void OnActiveAccountLogout() OVERRIDE;
56
57 // GCMDriver overrides: 51 // GCMDriver overrides:
58 virtual void Shutdown() OVERRIDE; 52 virtual void Shutdown() OVERRIDE;
53 virtual void OnSignedIn() OVERRIDE;
54 virtual void Purge() OVERRIDE;
59 virtual void AddAppHandler(const std::string& app_id, 55 virtual void AddAppHandler(const std::string& app_id,
60 GCMAppHandler* handler) OVERRIDE; 56 GCMAppHandler* handler) OVERRIDE;
61 virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; 57 virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
62 58
63 // GCMDriver implementation: 59 // GCMDriver implementation:
64 virtual void Enable() OVERRIDE; 60 virtual void Enable() OVERRIDE;
65 virtual void Disable() OVERRIDE; 61 virtual void Disable() OVERRIDE;
66 virtual GCMClient* GetGCMClientForTesting() const OVERRIDE; 62 virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
67 virtual bool IsStarted() const OVERRIDE; 63 virtual bool IsStarted() const OVERRIDE;
68 virtual bool IsGCMClientReady() const OVERRIDE; 64 virtual bool IsGCMClientReady() const OVERRIDE;
69 virtual bool IsConnected() const OVERRIDE; 65 virtual bool IsConnected() const OVERRIDE;
70 virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback, 66 virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback,
71 bool clear_logs) OVERRIDE; 67 bool clear_logs) OVERRIDE;
72 virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback, 68 virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
73 bool recording) OVERRIDE; 69 bool recording) OVERRIDE;
74 virtual std::string SignedInUserName() const OVERRIDE;
75 70
76 protected: 71 protected:
77 // GCMDriver implementation: 72 // GCMDriver implementation:
78 virtual GCMClient::Result EnsureStarted() OVERRIDE; 73 virtual GCMClient::Result EnsureStarted() OVERRIDE;
79 virtual void RegisterImpl( 74 virtual void RegisterImpl(
80 const std::string& app_id, 75 const std::string& app_id,
81 const std::vector<std::string>& sender_ids) OVERRIDE; 76 const std::vector<std::string>& sender_ids) OVERRIDE;
82 virtual void UnregisterImpl(const std::string& app_id) OVERRIDE; 77 virtual void UnregisterImpl(const std::string& app_id) OVERRIDE;
83 virtual void SendImpl(const std::string& app_id, 78 virtual void SendImpl(const std::string& app_id,
84 const std::string& receiver_id, 79 const std::string& receiver_id,
85 const GCMClient::OutgoingMessage& message) OVERRIDE; 80 const GCMClient::OutgoingMessage& message) OVERRIDE;
86 81
87 private: 82 private:
88 class DelayedTaskController; 83 class DelayedTaskController;
89 class IOWorker; 84 class IOWorker;
90 85
91 // Stops the GCM service. It can be restarted by calling EnsureStarted again. 86 // Stops the GCM service. It can be restarted by calling EnsureStarted again.
92 void Stop(); 87 void Stop();
93 88
94 // Remove cached data when GCM service is stopped. 89 // Remove cached data when GCM service is stopped.
95 void RemoveCachedData(); 90 void RemoveCachedData();
96 91
97 // Checks out of GCM and erases any cached and persisted data.
98 void CheckOut();
99
100 void DoRegister(const std::string& app_id, 92 void DoRegister(const std::string& app_id,
101 const std::vector<std::string>& sender_ids); 93 const std::vector<std::string>& sender_ids);
102 void DoUnregister(const std::string& app_id); 94 void DoUnregister(const std::string& app_id);
103 void DoSend(const std::string& app_id, 95 void DoSend(const std::string& app_id,
104 const std::string& receiver_id, 96 const std::string& receiver_id,
105 const GCMClient::OutgoingMessage& message); 97 const GCMClient::OutgoingMessage& message);
106 98
107 // Callbacks posted from IO thread to UI thread. 99 // Callbacks posted from IO thread to UI thread.
108 void MessageReceived(const std::string& app_id, 100 void MessageReceived(const std::string& app_id,
109 const GCMClient::IncomingMessage& message); 101 const GCMClient::IncomingMessage& message);
110 void MessagesDeleted(const std::string& app_id); 102 void MessagesDeleted(const std::string& app_id);
111 void MessageSendError(const std::string& app_id, 103 void MessageSendError(const std::string& app_id,
112 const GCMClient::SendErrorDetails& send_error_details); 104 const GCMClient::SendErrorDetails& send_error_details);
113 void GCMClientReady(); 105 void GCMClientReady();
114 void OnConnected(const net::IPEndPoint& ip_endpoint); 106 void OnConnected(const net::IPEndPoint& ip_endpoint);
115 void OnDisconnected(); 107 void OnDisconnected();
116 108
117 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); 109 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats);
118 110
111 // Flag to indicate whether the user is signed in to a GAIA account.
112 // TODO(jianli): To be removed when sign-in enforcement is dropped.
113 bool signed_in_;
114
115 // Flag to indicate if GCM is started.
116 bool gcm_started_;
117
119 // Flag to indicate if GCM is enabled. 118 // Flag to indicate if GCM is enabled.
120 bool gcm_enabled_; 119 bool gcm_enabled_;
121 120
122 // Flag to indicate if GCMClient is ready. 121 // Flag to indicate if GCMClient is ready.
123 bool gcm_client_ready_; 122 bool gcm_client_ready_;
124 123
125 // Flag to indicate the last known state of the GCM client. Because this 124 // Flag to indicate the last known state of the GCM client. Because this
126 // flag lives on the UI thread, while the GCM client lives on the IO thread, 125 // flag lives on the UI thread, while the GCM client lives on the IO thread,
127 // it may be out of date while connection changes are happening. 126 // it may be out of date while connection changes are happening.
128 bool connected_; 127 bool connected_;
129 128
130 // The account ID that this service is responsible for. Empty when the service
131 // is not running.
132 std::string account_id_;
133
134 scoped_ptr<IdentityProvider> identity_provider_;
135 scoped_refptr<base::SequencedTaskRunner> ui_thread_; 129 scoped_refptr<base::SequencedTaskRunner> ui_thread_;
136 scoped_refptr<base::SequencedTaskRunner> io_thread_; 130 scoped_refptr<base::SequencedTaskRunner> io_thread_;
137 131
138 scoped_ptr<DelayedTaskController> delayed_task_controller_; 132 scoped_ptr<DelayedTaskController> delayed_task_controller_;
139 133
140 // For all the work occurring on the IO thread. Must be destroyed on the IO 134 // For all the work occurring on the IO thread. Must be destroyed on the IO
141 // thread. 135 // thread.
142 scoped_ptr<IOWorker> io_worker_; 136 scoped_ptr<IOWorker> io_worker_;
143 137
144 // Callback for GetGCMStatistics. 138 // Callback for GetGCMStatistics.
145 GetGCMStatisticsCallback request_gcm_statistics_callback_; 139 GetGCMStatisticsCallback request_gcm_statistics_callback_;
146 140
147 // Used to pass a weak pointer to the IO worker. 141 // Used to pass a weak pointer to the IO worker.
148 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; 142 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_;
149 143
150 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); 144 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop);
151 }; 145 };
152 146
153 } // namespace gcm 147 } // namespace gcm
154 148
155 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ 149 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_android.cc ('k') | components/gcm_driver/gcm_driver_desktop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698