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

Side by Side Diff: chrome/browser/extensions/api/gcm/gcm_api.cc

Issue 225403021: Extract Profile-independent GCMService from GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Provide GCMService with the list of all accounts. It does use it after all. Created 6 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/extensions/api/gcm/gcm_api.h" 5 #include "chrome/browser/extensions/api/gcm/gcm_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/services/gcm/gcm_profile_service.h" 15 #include "chrome/browser/services/gcm/gcm_profile_service.h"
16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
17 #include "chrome/browser/services/gcm/gcm_service.h"
17 #include "chrome/common/extensions/api/gcm.h" 18 #include "chrome/common/extensions/api/gcm.h"
18 #include "extensions/browser/extension_system.h" 19 #include "extensions/browser/extension_system.h"
19 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
20 21
21 namespace { 22 namespace {
22 23
23 const size_t kMaximumMessageSize = 4096; // in bytes. 24 const size_t kMaximumMessageSize = 4096; // in bytes.
24 const char kCollapseKey[] = "collapse_key"; 25 const char kCollapseKey[] = "collapse_key";
25 const char kGoogDotRestrictedPrefix[] = "goog."; 26 const char kGoogDotRestrictedPrefix[] = "goog.";
26 const char kGoogleRestrictedPrefix[] = "google"; 27 const char kGoogleRestrictedPrefix[] = "google";
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 Profile* profile = Profile::FromBrowserContext(browser_context()); 91 Profile* profile = Profile::FromBrowserContext(browser_context());
91 92
92 // GCM is not supported in incognito mode. 93 // GCM is not supported in incognito mode.
93 if (profile->IsOffTheRecord()) 94 if (profile->IsOffTheRecord())
94 return false; 95 return false;
95 96
96 return gcm::GCMProfileService::GetGCMEnabledState(profile) != 97 return gcm::GCMProfileService::GetGCMEnabledState(profile) !=
97 gcm::GCMProfileService::ALWAYS_DISABLED; 98 gcm::GCMProfileService::ALWAYS_DISABLED;
98 } 99 }
99 100
100 gcm::GCMProfileService* GcmApiFunction::GCMProfileService() const { 101 gcm::GCMService* GcmApiFunction::GCMService() const {
jianli 2014/04/17 00:33:19 GCMProfileServiceFactory::GetForProfile returns GC
bartfab (slow) 2014/04/17 14:20:01 Done.
101 return gcm::GCMProfileServiceFactory::GetForProfile( 102 return gcm::GCMProfileServiceFactory::GetForProfile(
102 Profile::FromBrowserContext(browser_context())); 103 Profile::FromBrowserContext(browser_context()));
103 } 104 }
104 105
105 GcmRegisterFunction::GcmRegisterFunction() {} 106 GcmRegisterFunction::GcmRegisterFunction() {}
106 107
107 GcmRegisterFunction::~GcmRegisterFunction() {} 108 GcmRegisterFunction::~GcmRegisterFunction() {}
108 109
109 bool GcmRegisterFunction::DoWork() { 110 bool GcmRegisterFunction::DoWork() {
110 scoped_ptr<api::gcm::Register::Params> params( 111 scoped_ptr<api::gcm::Register::Params> params(
111 api::gcm::Register::Params::Create(*args_)); 112 api::gcm::Register::Params::Create(*args_));
112 EXTENSION_FUNCTION_VALIDATE(params.get()); 113 EXTENSION_FUNCTION_VALIDATE(params.get());
113 114
114 GCMProfileService()->Register( 115 GCMService()->Register(
115 GetExtension()->id(), 116 GetExtension()->id(),
116 params->sender_ids, 117 params->sender_ids,
117 base::Bind(&GcmRegisterFunction::CompleteFunctionWithResult, this)); 118 base::Bind(&GcmRegisterFunction::CompleteFunctionWithResult, this));
118 119
119 return true; 120 return true;
120 } 121 }
121 122
122 void GcmRegisterFunction::CompleteFunctionWithResult( 123 void GcmRegisterFunction::CompleteFunctionWithResult(
123 const std::string& registration_id, 124 const std::string& registration_id,
124 gcm::GCMClient::Result result) { 125 gcm::GCMClient::Result result) {
125 SetResult(new base::StringValue(registration_id)); 126 SetResult(new base::StringValue(registration_id));
126 SetError(GcmResultToError(result)); 127 SetError(GcmResultToError(result));
127 SendResponse(gcm::GCMClient::SUCCESS == result); 128 SendResponse(gcm::GCMClient::SUCCESS == result);
128 } 129 }
129 130
130 GcmUnregisterFunction::GcmUnregisterFunction() {} 131 GcmUnregisterFunction::GcmUnregisterFunction() {}
131 132
132 GcmUnregisterFunction::~GcmUnregisterFunction() {} 133 GcmUnregisterFunction::~GcmUnregisterFunction() {}
133 134
134 bool GcmUnregisterFunction::DoWork() { 135 bool GcmUnregisterFunction::DoWork() {
135 GCMProfileService()->Unregister( 136 GCMService()->Unregister(
136 GetExtension()->id(), 137 GetExtension()->id(),
137 base::Bind(&GcmUnregisterFunction::CompleteFunctionWithResult, this)); 138 base::Bind(&GcmUnregisterFunction::CompleteFunctionWithResult, this));
138 139
139 return true; 140 return true;
140 } 141 }
141 142
142 void GcmUnregisterFunction::CompleteFunctionWithResult( 143 void GcmUnregisterFunction::CompleteFunctionWithResult(
143 gcm::GCMClient::Result result) { 144 gcm::GCMClient::Result result) {
144 SetError(GcmResultToError(result)); 145 SetError(GcmResultToError(result));
145 SendResponse(gcm::GCMClient::SUCCESS == result); 146 SendResponse(gcm::GCMClient::SUCCESS == result);
146 } 147 }
147 148
148 GcmSendFunction::GcmSendFunction() {} 149 GcmSendFunction::GcmSendFunction() {}
149 150
150 GcmSendFunction::~GcmSendFunction() {} 151 GcmSendFunction::~GcmSendFunction() {}
151 152
152 bool GcmSendFunction::DoWork() { 153 bool GcmSendFunction::DoWork() {
153 scoped_ptr<api::gcm::Send::Params> params( 154 scoped_ptr<api::gcm::Send::Params> params(
154 api::gcm::Send::Params::Create(*args_)); 155 api::gcm::Send::Params::Create(*args_));
155 EXTENSION_FUNCTION_VALIDATE(params.get()); 156 EXTENSION_FUNCTION_VALIDATE(params.get());
156 EXTENSION_FUNCTION_VALIDATE( 157 EXTENSION_FUNCTION_VALIDATE(
157 ValidateMessageData(params->message.data.additional_properties)); 158 ValidateMessageData(params->message.data.additional_properties));
158 159
159 gcm::GCMClient::OutgoingMessage outgoing_message; 160 gcm::GCMClient::OutgoingMessage outgoing_message;
160 outgoing_message.id = params->message.message_id; 161 outgoing_message.id = params->message.message_id;
161 outgoing_message.data = params->message.data.additional_properties; 162 outgoing_message.data = params->message.data.additional_properties;
162 if (params->message.time_to_live.get()) 163 if (params->message.time_to_live.get())
163 outgoing_message.time_to_live = *params->message.time_to_live; 164 outgoing_message.time_to_live = *params->message.time_to_live;
164 165
165 GCMProfileService()->Send( 166 GCMService()->Send(
166 GetExtension()->id(), 167 GetExtension()->id(),
167 params->message.destination_id, 168 params->message.destination_id,
168 outgoing_message, 169 outgoing_message,
169 base::Bind(&GcmSendFunction::CompleteFunctionWithResult, this)); 170 base::Bind(&GcmSendFunction::CompleteFunctionWithResult, this));
170 171
171 return true; 172 return true;
172 } 173 }
173 174
174 void GcmSendFunction::CompleteFunctionWithResult( 175 void GcmSendFunction::CompleteFunctionWithResult(
175 const std::string& message_id, 176 const std::string& message_id,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 256
256 void GcmJsEventRouter::OnListenerAdded(const EventListenerInfo& details) { 257 void GcmJsEventRouter::OnListenerAdded(const EventListenerInfo& details) {
257 if (gcm::GCMProfileService::GetGCMEnabledState(profile_) == 258 if (gcm::GCMProfileService::GetGCMEnabledState(profile_) ==
258 gcm::GCMProfileService::ALWAYS_DISABLED) { 259 gcm::GCMProfileService::ALWAYS_DISABLED) {
259 return; 260 return;
260 } 261 }
261 gcm::GCMProfileServiceFactory::GetForProfile(profile_)->Start(); 262 gcm::GCMProfileServiceFactory::GetForProfile(profile_)->Start();
262 } 263 }
263 264
264 } // namespace extensions 265 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698