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

Side by Side Diff: chrome/browser/media/router/media_router_feature.cc

Issue 1907673002: [Media Router] Ensure the same FeatureSwitch is used for lifetime of the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | 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/media/router/media_router_feature.h" 5 #include "chrome/browser/media/router/media_router_feature.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "content/public/browser/browser_context.h" 8 #include "content/public/browser/browser_context.h"
9 9
10 #if defined(ENABLE_EXTENSIONS) 10 #if defined(ENABLE_EXTENSIONS)
11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h" 11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h"
12 #include "extensions/browser/extension_registry.h" 12 #include "extensions/browser/extension_registry.h"
13 #include "extensions/common/extension_set.h" 13 #include "extensions/common/extension_set.h"
14 #include "extensions/common/feature_switch.h" 14 #include "extensions/common/feature_switch.h"
15 #endif 15 #endif
16 16
17 namespace media_router { 17 namespace media_router {
18 18
19 #if defined(ENABLE_MEDIA_ROUTER) && defined(ENABLE_EXTENSIONS)
20 namespace {
21
22 bool HasCastExtension(content::BrowserContext* context) {
23 extensions::ExtensionRegistry* registry =
24 extensions::ExtensionRegistry::Get(context);
25 if (!registry) {
26 DLOG(ERROR) << "ExtensionRegistry is null. Assume no cast extension "
27 "installed.";
28 return false;
29 }
30
31 const extensions::ExtensionSet& extension_set =
32 registry->enabled_extensions();
33 return extension_set.Contains(extensions::kStableChromecastExtensionId) ||
34 extension_set.Contains(extensions::kBetaChromecastExtensionId);
35 }
36
37 } // namespace
38 #endif // defined(ENABLE_MEDIA_ROUTER) && defined(ENABLE_EXTENSIONS)
39
19 bool MediaRouterEnabled(content::BrowserContext* context) { 40 bool MediaRouterEnabled(content::BrowserContext* context) {
20 #if defined(ENABLE_MEDIA_ROUTER) 41 #if defined(ENABLE_MEDIA_ROUTER)
21 #if defined(OS_ANDROID) 42 #if defined(OS_ANDROID)
22 return true; 43 return true;
23 #elif defined(ENABLE_EXTENSIONS) 44 #elif defined(ENABLE_EXTENSIONS)
24 extensions::ExtensionRegistry* registry = 45 // |has_cast_extension| being static means that we determine which
25 extensions::ExtensionRegistry::Get(context); 46 // FeatureSwitch to use only on first invocation of this function. The same
26 if (!registry) { 47 // switch will be used for the lifetime of the browser. Note that the browser
27 DLOG(ERROR) << "ExtensionRegistry is null. Assume no cast extension " 48 // expects the same value to be returned by repeated calls to this function,
28 "installed."; 49 // since it will result in inconsistent behaviors otherwise.
29 return extensions::FeatureSwitch::media_router()->IsEnabled(); 50 // The caveat is we only use the BrowserContext the function is first called
30 } 51 // with to determine which field trial to use for the lifetime of the browser.
31 52 static bool has_cast_extension = HasCastExtension(context);
mark a. foltz 2016/04/21 19:30:56 This needs to be per-|context|, since one profile
32 const extensions::ExtensionSet& extension_set = 53 extensions::FeatureSwitch* feature_switch =
33 registry->enabled_extensions(); 54 has_cast_extension
34 if (extension_set.Contains(extensions::kStableChromecastExtensionId) || 55 ? extensions::FeatureSwitch::media_router_with_cast_extension()
35 extension_set.Contains(extensions::kBetaChromecastExtensionId)) { 56 : extensions::FeatureSwitch::media_router();
36 return extensions::FeatureSwitch::media_router_with_cast_extension() 57 return feature_switch->IsEnabled();
37 ->IsEnabled();
38 }
39
40 return extensions::FeatureSwitch::media_router()->IsEnabled();
41 #else // !defined(ENABLE_EXTENSIONS) 58 #else // !defined(ENABLE_EXTENSIONS)
42 return false; 59 return false;
43 #endif // defined(OS_ANDROID) 60 #endif // defined(OS_ANDROID)
mark a. foltz 2016/04/21 19:30:56 There are only two #if's above, but there are thre
44 #else // !defined(ENABLE_MEDIA_ROUTER) 61 #else // !defined(ENABLE_MEDIA_ROUTER)
45 return false; 62 return false;
46 #endif // defined(ENABLE_MEDIA_ROUTER) 63 #endif // defined(ENABLE_MEDIA_ROUTER)
47 } 64 }
48 65
49 } // namespace media_router 66 } // namespace media_router
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698