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

Side by Side Diff: chrome/browser/extensions/api/instance_id/instance_id_api.cc

Issue 1731913002: Move InstanceID field trial check to extension-specific code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | components/gcm_driver/instance_id/instance_id_driver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/instance_id/instance_id_api.h" 5 #include "chrome/browser/extensions/api/instance_id/instance_id_api.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/field_trial.h"
8 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service.h" 11 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service.h"
11 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_fa ctory.h" 12 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_fa ctory.h"
12 #include "chrome/common/extensions/api/instance_id.h" 13 #include "chrome/common/extensions/api/instance_id.h"
13 #include "components/gcm_driver/instance_id/instance_id_driver.h" 14 #include "components/gcm_driver/instance_id/instance_id_driver.h"
14 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
15 16
16 namespace extensions { 17 namespace extensions {
17 18
18 namespace { 19 namespace {
19 20
21 const char kInstanceIDFieldTrialName[] = "InstanceID";
22 const char kInstanceIDFieldTrialEnabledGroupName[] = "Enabled";
23
20 // Error messages. 24 // Error messages.
21 const char kInvalidParameter[] = "Function was called with invalid parameters."; 25 const char kInvalidParameter[] = "Function was called with invalid parameters.";
22 const char kDisabled[] = "Instance ID is currently disabled."; 26 const char kDisabled[] = "Instance ID is currently disabled.";
23 const char kAsyncOperationPending[] = "Asynchronous operation is pending."; 27 const char kAsyncOperationPending[] = "Asynchronous operation is pending.";
24 const char kNetworkError[] = "Network error occurred."; 28 const char kNetworkError[] = "Network error occurred.";
25 const char kServerError[] = "Server error occurred."; 29 const char kServerError[] = "Server error occurred.";
26 const char kUnknownError[] = "Unknown error occurred."; 30 const char kUnknownError[] = "Unknown error occurred.";
27 31
28 const char* InstanceIDResultToError(instance_id::InstanceID::Result result) { 32 const char* InstanceIDResultToError(instance_id::InstanceID::Result result) {
29 switch (result) { 33 switch (result) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return RespondNow(Error( 71 return RespondNow(Error(
68 InstanceIDResultToError(instance_id::InstanceID::DISABLED))); 72 InstanceIDResultToError(instance_id::InstanceID::DISABLED)));
69 } 73 }
70 74
71 return DoWork(); 75 return DoWork();
72 } 76 }
73 77
74 bool InstanceIDApiFunction::IsEnabled() const { 78 bool InstanceIDApiFunction::IsEnabled() const {
75 Profile* profile = Profile::FromBrowserContext(browser_context()); 79 Profile* profile = Profile::FromBrowserContext(browser_context());
76 80
77 return instance_id::InstanceIDProfileService::IsInstanceIDEnabled(profile); 81 if (!instance_id::InstanceIDProfileService::IsInstanceIDEnabled(profile))
82 return false;
83
84 std::string group_name =
85 base::FieldTrialList::FindFullName(kInstanceIDFieldTrialName);
86 return group_name == kInstanceIDFieldTrialEnabledGroupName;
78 } 87 }
79 88
80 instance_id::InstanceID* InstanceIDApiFunction::GetInstanceID() const { 89 instance_id::InstanceID* InstanceIDApiFunction::GetInstanceID() const {
81 return instance_id::InstanceIDProfileServiceFactory::GetForProfile( 90 return instance_id::InstanceIDProfileServiceFactory::GetForProfile(
82 Profile::FromBrowserContext(browser_context()))->driver()-> 91 Profile::FromBrowserContext(browser_context()))->driver()->
83 GetInstanceID(extension()->id()); 92 GetInstanceID(extension()->id());
84 } 93 }
85 94
86 InstanceIDGetIDFunction::InstanceIDGetIDFunction() {} 95 InstanceIDGetIDFunction::InstanceIDGetIDFunction() {}
87 96
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 191
183 void InstanceIDDeleteIDFunction::DeleteIDCompleted( 192 void InstanceIDDeleteIDFunction::DeleteIDCompleted(
184 instance_id::InstanceID::Result result) { 193 instance_id::InstanceID::Result result) {
185 if (result == instance_id::InstanceID::SUCCESS) 194 if (result == instance_id::InstanceID::SUCCESS)
186 Respond(NoArguments()); 195 Respond(NoArguments());
187 else 196 else
188 Respond(Error(InstanceIDResultToError(result))); 197 Respond(Error(InstanceIDResultToError(result)));
189 } 198 }
190 199
191 } // namespace extensions 200 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | components/gcm_driver/instance_id/instance_id_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698