OLD | NEW |
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 static bool g_channel_checking_enabled = false; |
66 | 66 |
67 class Channel { | 67 class Channel { |
68 public: | 68 public: |
69 VersionInfo::Channel GetChannel() { | 69 VersionInfo::Channel GetChannel() { |
70 CHECK(g_channel_checking_enabled); | 70 CHECK(channel_.get()); |
71 if (channel_for_testing_.get()) | 71 return *channel_; |
72 return *channel_for_testing_; | |
73 return VersionInfo::GetChannel(); | |
74 } | 72 } |
75 | 73 |
76 void SetChannelForTesting(VersionInfo::Channel channel_for_testing) { | 74 bool HasChannel() { |
77 channel_for_testing_.reset(new VersionInfo::Channel(channel_for_testing)); | 75 return channel_.get(); |
78 } | 76 } |
79 | 77 |
80 void ResetChannelForTesting() { | 78 void SetChannel(VersionInfo::Channel channel) { |
81 channel_for_testing_.reset(); | 79 channel_.reset(new VersionInfo::Channel(channel)); |
| 80 } |
| 81 |
| 82 void ClearChannel() { |
| 83 channel_.reset(); |
82 } | 84 } |
83 | 85 |
84 private: | 86 private: |
85 scoped_ptr<VersionInfo::Channel> channel_for_testing_; | 87 scoped_ptr<VersionInfo::Channel> channel_; |
86 }; | 88 }; |
87 | 89 |
88 static base::LazyInstance<Channel> g_channel = LAZY_INSTANCE_INITIALIZER; | 90 static base::LazyInstance<Channel> g_channel = LAZY_INSTANCE_INITIALIZER; |
89 | 91 |
90 // TODO(aa): Can we replace all this manual parsing with JSON schema stuff? | 92 // TODO(aa): Can we replace all this manual parsing with JSON schema stuff? |
91 | 93 |
92 void ParseSet(const DictionaryValue* value, | 94 void ParseSet(const DictionaryValue* value, |
93 const std::string& property, | 95 const std::string& property, |
94 std::set<std::string>* set) { | 96 std::set<std::string>* set) { |
95 const ListValue* list_value = NULL; | 97 const ListValue* list_value = NULL; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 315 |
314 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) | 316 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) |
315 return INVALID_PLATFORM; | 317 return INVALID_PLATFORM; |
316 | 318 |
317 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) | 319 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) |
318 return INVALID_MIN_MANIFEST_VERSION; | 320 return INVALID_MIN_MANIFEST_VERSION; |
319 | 321 |
320 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) | 322 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) |
321 return INVALID_MAX_MANIFEST_VERSION; | 323 return INVALID_MAX_MANIFEST_VERSION; |
322 | 324 |
323 if (g_channel_checking_enabled) { | 325 if (g_channel.Get().HasChannel()) { |
324 if (channel_ < g_channel.Get().GetChannel()) | 326 if (channel_ < g_channel.Get().GetChannel()) |
325 return UNSUPPORTED_CHANNEL; | 327 return UNSUPPORTED_CHANNEL; |
| 328 } else { |
| 329 // Would warn here, but it'd be very spammy in tests. |
326 } | 330 } |
327 | 331 |
328 return IS_AVAILABLE; | 332 return IS_AVAILABLE; |
329 } | 333 } |
330 | 334 |
331 Feature::Availability Feature::IsAvailableToContext( | 335 Feature::Availability Feature::IsAvailableToContext( |
332 const Extension* extension, | 336 const Extension* extension, |
333 Feature::Context context, | 337 Feature::Context context, |
334 Feature::Platform platform) const { | 338 Feature::Platform platform) const { |
335 Availability result = IsAvailableToManifest( | 339 Availability result = IsAvailableToManifest( |
336 extension->id(), | 340 extension->id(), |
337 extension->GetType(), | 341 extension->GetType(), |
338 ConvertLocation(extension->location()), | 342 ConvertLocation(extension->location()), |
339 extension->manifest_version(), | 343 extension->manifest_version(), |
340 platform); | 344 platform); |
341 if (result != IS_AVAILABLE) | 345 if (result != IS_AVAILABLE) |
342 return result; | 346 return result; |
343 | 347 |
344 if (!contexts_.empty() && | 348 if (!contexts_.empty() && |
345 contexts_.find(context) == contexts_.end()) { | 349 contexts_.find(context) == contexts_.end()) { |
346 return INVALID_CONTEXT; | 350 return INVALID_CONTEXT; |
347 } | 351 } |
348 | 352 |
349 return IS_AVAILABLE; | 353 return IS_AVAILABLE; |
350 } | 354 } |
351 | 355 |
352 // static | 356 // static |
353 void Feature::SetChannelCheckingEnabled(bool enabled) { | 357 bool Feature::HasCurrentChannel() { |
354 g_channel_checking_enabled = enabled; | 358 return g_channel.Get().HasChannel(); |
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 } | 359 } |
371 | 360 |
372 // static | 361 // static |
373 chrome::VersionInfo::Channel Feature::GetCurrentChannel() { | 362 chrome::VersionInfo::Channel Feature::GetCurrentChannel() { |
374 if (g_channel_checking_enabled) | 363 CHECK(g_channel.Get().HasChannel()) << "No channel has been set."; |
375 return g_channel.Get().GetChannel(); | 364 return g_channel.Get().GetChannel(); |
376 return chrome::VersionInfo::GetChannel(); | 365 } |
| 366 |
| 367 // static |
| 368 void Feature::SetCurrentChannel(VersionInfo::Channel channel) { |
| 369 g_channel.Get().SetChannel(channel); |
| 370 } |
| 371 |
| 372 // static |
| 373 void Feature::ClearCurrentChannel() { |
| 374 g_channel.Get().ClearChannel(); |
377 } | 375 } |
378 | 376 |
379 } // namespace | 377 } // namespace |
OLD | NEW |