OLD | NEW |
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/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/services/gcm/gcm_profile_service.h" | |
17 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
18 #include "chrome/common/extensions/api/gcm.h" | 17 #include "chrome/common/extensions/api/gcm.h" |
19 #include "components/gcm_driver/common/gcm_messages.h" | 18 #include "components/gcm_driver/common/gcm_messages.h" |
20 #include "components/gcm_driver/gcm_driver.h" | 19 #include "components/gcm_driver/gcm_driver.h" |
| 20 #include "components/gcm_driver/gcm_profile_service.h" |
21 #include "extensions/browser/event_router.h" | 21 #include "extensions/browser/event_router.h" |
22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const size_t kMaximumMessageSize = 4096; // in bytes. | 26 const size_t kMaximumMessageSize = 4096; // in bytes. |
27 const char kCollapseKey[] = "collapse_key"; | 27 const char kCollapseKey[] = "collapse_key"; |
28 const char kGoogDotRestrictedPrefix[] = "goog."; | 28 const char kGoogDotRestrictedPrefix[] = "goog."; |
29 const char kGoogleRestrictedPrefix[] = "google"; | 29 const char kGoogleRestrictedPrefix[] = "google"; |
30 | 30 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return DoWork(); | 89 return DoWork(); |
90 } | 90 } |
91 | 91 |
92 bool GcmApiFunction::IsGcmApiEnabled() const { | 92 bool GcmApiFunction::IsGcmApiEnabled() const { |
93 Profile* profile = Profile::FromBrowserContext(browser_context()); | 93 Profile* profile = Profile::FromBrowserContext(browser_context()); |
94 | 94 |
95 // GCM is not supported in incognito mode. | 95 // GCM is not supported in incognito mode. |
96 if (profile->IsOffTheRecord()) | 96 if (profile->IsOffTheRecord()) |
97 return false; | 97 return false; |
98 | 98 |
99 return gcm::GCMProfileService::IsGCMEnabled(profile); | 99 return gcm::GCMProfileService::IsGCMEnabled(profile->GetPrefs()); |
100 } | 100 } |
101 | 101 |
102 gcm::GCMDriver* GcmApiFunction::GetGCMDriver() const { | 102 gcm::GCMDriver* GcmApiFunction::GetGCMDriver() const { |
103 return gcm::GCMProfileServiceFactory::GetForProfile( | 103 return gcm::GCMProfileServiceFactory::GetForProfile( |
104 Profile::FromBrowserContext(browser_context()))->driver(); | 104 Profile::FromBrowserContext(browser_context()))->driver(); |
105 } | 105 } |
106 | 106 |
107 GcmRegisterFunction::GcmRegisterFunction() {} | 107 GcmRegisterFunction::GcmRegisterFunction() {} |
108 | 108 |
109 GcmRegisterFunction::~GcmRegisterFunction() {} | 109 GcmRegisterFunction::~GcmRegisterFunction() {} |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 error.error_message = GcmResultToError(send_error_details.result); | 235 error.error_message = GcmResultToError(send_error_details.result); |
236 error.details.additional_properties = send_error_details.additional_data; | 236 error.details.additional_properties = send_error_details.additional_data; |
237 | 237 |
238 scoped_ptr<Event> event( | 238 scoped_ptr<Event> event( |
239 new Event(events::GCM_ON_SEND_ERROR, api::gcm::OnSendError::kEventName, | 239 new Event(events::GCM_ON_SEND_ERROR, api::gcm::OnSendError::kEventName, |
240 api::gcm::OnSendError::Create(error).Pass(), profile_)); | 240 api::gcm::OnSendError::Create(error).Pass(), profile_)); |
241 EventRouter::Get(profile_)->DispatchEventToExtension(app_id, event.Pass()); | 241 EventRouter::Get(profile_)->DispatchEventToExtension(app_id, event.Pass()); |
242 } | 242 } |
243 | 243 |
244 } // namespace extensions | 244 } // namespace extensions |
OLD | NEW |