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

Side by Side Diff: chrome/common/extensions/features/feature.cc

Issue 10826199: Properly propagate the current Chrome channel into the Feature system on the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make the default stable Created 8 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/extensions/features/feature.h" 5 #include "chrome/common/extensions/features/feature.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 channels["stable"] = VersionInfo::CHANNEL_STABLE; 42 channels["stable"] = VersionInfo::CHANNEL_STABLE;
43 } 43 }
44 44
45 std::map<std::string, Extension::Type> extension_types; 45 std::map<std::string, Extension::Type> extension_types;
46 std::map<std::string, extensions::Feature::Context> contexts; 46 std::map<std::string, extensions::Feature::Context> contexts;
47 std::map<std::string, extensions::Feature::Location> locations; 47 std::map<std::string, extensions::Feature::Location> locations;
48 std::map<std::string, extensions::Feature::Platform> platforms; 48 std::map<std::string, extensions::Feature::Platform> platforms;
49 std::map<std::string, VersionInfo::Channel> channels; 49 std::map<std::string, VersionInfo::Channel> channels;
50 }; 50 };
51 51
52 static base::LazyInstance<Mappings> g_mappings = LAZY_INSTANCE_INITIALIZER; 52 base::LazyInstance<Mappings> g_mappings = LAZY_INSTANCE_INITIALIZER;
53 53
54 std::string GetChannelName(VersionInfo::Channel channel) { 54 std::string GetChannelName(VersionInfo::Channel channel) {
55 typedef std::map<std::string, VersionInfo::Channel> ChannelsMap; 55 typedef std::map<std::string, VersionInfo::Channel> ChannelsMap;
56 ChannelsMap channels = g_mappings.Get().channels; 56 ChannelsMap channels = g_mappings.Get().channels;
57 for (ChannelsMap::iterator i = channels.begin(); i != channels.end(); ++i) { 57 for (ChannelsMap::iterator i = channels.begin(); i != channels.end(); ++i) {
58 if (i->second == channel) 58 if (i->second == channel)
59 return i->first; 59 return i->first;
60 } 60 }
61 NOTREACHED(); 61 NOTREACHED();
62 return "unknown"; 62 return "unknown";
63 } 63 }
64 64
65 static bool g_channel_checking_enabled = false; 65 VersionInfo::Channel g_current_channel = VersionInfo::CHANNEL_STABLE;
66
67 class Channel {
68 public:
69 VersionInfo::Channel GetChannel() {
70 CHECK(g_channel_checking_enabled);
71 if (channel_for_testing_.get())
72 return *channel_for_testing_;
73 return VersionInfo::GetChannel();
74 }
75
76 void SetChannelForTesting(VersionInfo::Channel channel_for_testing) {
77 channel_for_testing_.reset(new VersionInfo::Channel(channel_for_testing));
78 }
79
80 void ResetChannelForTesting() {
81 channel_for_testing_.reset();
82 }
83
84 private:
85 scoped_ptr<VersionInfo::Channel> channel_for_testing_;
86 };
87
88 static base::LazyInstance<Channel> g_channel = LAZY_INSTANCE_INITIALIZER;
89 66
90 // TODO(aa): Can we replace all this manual parsing with JSON schema stuff? 67 // TODO(aa): Can we replace all this manual parsing with JSON schema stuff?
91 68
92 void ParseSet(const DictionaryValue* value, 69 void ParseSet(const DictionaryValue* value,
93 const std::string& property, 70 const std::string& property,
94 std::set<std::string>* set) { 71 std::set<std::string>* set) {
95 const ListValue* list_value = NULL; 72 const ListValue* list_value = NULL;
96 if (!value->GetList(property, &list_value)) 73 if (!value->GetList(property, &list_value))
97 return; 74 return;
98 75
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 290
314 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) 291 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform)
315 return INVALID_PLATFORM; 292 return INVALID_PLATFORM;
316 293
317 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) 294 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_)
318 return INVALID_MIN_MANIFEST_VERSION; 295 return INVALID_MIN_MANIFEST_VERSION;
319 296
320 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) 297 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_)
321 return INVALID_MAX_MANIFEST_VERSION; 298 return INVALID_MAX_MANIFEST_VERSION;
322 299
323 if (g_channel_checking_enabled) { 300 if (channel_ < g_current_channel)
324 if (channel_ < g_channel.Get().GetChannel()) 301 return UNSUPPORTED_CHANNEL;
325 return UNSUPPORTED_CHANNEL;
326 }
327 302
328 return IS_AVAILABLE; 303 return IS_AVAILABLE;
329 } 304 }
330 305
331 Feature::Availability Feature::IsAvailableToContext( 306 Feature::Availability Feature::IsAvailableToContext(
332 const Extension* extension, 307 const Extension* extension,
333 Feature::Context context, 308 Feature::Context context,
334 Feature::Platform platform) const { 309 Feature::Platform platform) const {
335 Availability result = IsAvailableToManifest( 310 Availability result = IsAvailableToManifest(
336 extension->id(), 311 extension->id(),
337 extension->GetType(), 312 extension->GetType(),
338 ConvertLocation(extension->location()), 313 ConvertLocation(extension->location()),
339 extension->manifest_version(), 314 extension->manifest_version(),
340 platform); 315 platform);
341 if (result != IS_AVAILABLE) 316 if (result != IS_AVAILABLE)
342 return result; 317 return result;
343 318
344 if (!contexts_.empty() && 319 if (!contexts_.empty() &&
345 contexts_.find(context) == contexts_.end()) { 320 contexts_.find(context) == contexts_.end()) {
346 return INVALID_CONTEXT; 321 return INVALID_CONTEXT;
347 } 322 }
348 323
349 return IS_AVAILABLE; 324 return IS_AVAILABLE;
350 } 325 }
351 326
352 // static 327 // static
353 void Feature::SetChannelCheckingEnabled(bool enabled) {
354 g_channel_checking_enabled = enabled;
355 }
356
357 // static
358 void Feature::ResetChannelCheckingEnabled() {
359 g_channel_checking_enabled = false;
360 }
361
362 // static
363 void Feature::SetChannelForTesting(VersionInfo::Channel channel) {
364 g_channel.Get().SetChannelForTesting(channel);
365 }
366
367 // static
368 void Feature::ResetChannelForTesting() {
369 g_channel.Get().ResetChannelForTesting();
370 }
371
372 // static
373 chrome::VersionInfo::Channel Feature::GetCurrentChannel() { 328 chrome::VersionInfo::Channel Feature::GetCurrentChannel() {
374 if (g_channel_checking_enabled) 329 return g_current_channel;
375 return g_channel.Get().GetChannel(); 330 }
376 return chrome::VersionInfo::GetChannel(); 331
332 // static
333 void Feature::SetCurrentChannel(VersionInfo::Channel channel) {
334 g_current_channel = channel;
377 } 335 }
378 336
379 } // namespace 337 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/extensions/features/feature.h ('k') | chrome/common/extensions/features/feature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698