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

Side by Side Diff: extensions/common/features/feature_channel.cc

Issue 2854293003: Fix losing of scoped feature channel in tests when it's equal to stable (Closed)
Patch Set: Take account of override count Created 3 years, 7 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 | « extensions/common/features/feature_channel.h ('k') | 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 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 "extensions/common/features/feature_channel.h" 5 #include "extensions/common/features/feature_channel.h"
6 6
7 #include "base/logging.h"
7 #include "components/version_info/version_info.h" 8 #include "components/version_info/version_info.h"
8 9
9 namespace { 10 namespace {
10 11
11 const version_info::Channel kDefaultChannel = version_info::Channel::STABLE; 12 // The current channel to be reported, unless overridden by
12 version_info::Channel g_current_channel = kDefaultChannel; 13 // |ScopedCurrentChannel|.
14 version_info::Channel g_current_channel = version_info::Channel::STABLE;
15
16 // The current channel overridden by |ScopedCurrentChannel|. The value is valid
17 // only whenever |g_override_count| is non-zero.
18 version_info::Channel g_overridden_channel = version_info::Channel::STABLE;
19
20 // The number of currently existing instances of |ScopedCurrentChannel|.
21 int g_override_count = 0;
13 22
14 } // namespace 23 } // namespace
15 24
16 namespace extensions { 25 namespace extensions {
17 26
18 version_info::Channel GetCurrentChannel() { 27 version_info::Channel GetCurrentChannel() {
19 return g_current_channel; 28 return g_override_count ? g_overridden_channel : g_current_channel;
20 } 29 }
21 30
22 void SetCurrentChannel(version_info::Channel channel) { 31 void SetCurrentChannel(version_info::Channel channel) {
23 g_current_channel = channel; 32 g_current_channel = channel;
24 } 33 }
25 34
26 version_info::Channel GetDefaultChannel() {
27 return kDefaultChannel;
28 }
29
30 ScopedCurrentChannel::ScopedCurrentChannel(version_info::Channel channel) 35 ScopedCurrentChannel::ScopedCurrentChannel(version_info::Channel channel)
31 : original_channel_(version_info::Channel::UNKNOWN) { 36 : channel_(channel),
32 original_channel_ = GetCurrentChannel(); 37 original_overridden_channel_(g_overridden_channel),
33 SetCurrentChannel(channel); 38 original_override_count_(g_override_count) {
39 g_overridden_channel = channel;
40 ++g_override_count;
34 } 41 }
35 42
36 ScopedCurrentChannel::~ScopedCurrentChannel() { 43 ScopedCurrentChannel::~ScopedCurrentChannel() {
37 SetCurrentChannel(original_channel_); 44 DCHECK_EQ(original_override_count_ + 1, g_override_count)
45 << "Scoped channel setters are not nested properly";
46 DCHECK_EQ(g_overridden_channel, channel_)
47 << "Scoped channel setters are not nested properly";
48 g_overridden_channel = original_overridden_channel_;
49 --g_override_count;
38 } 50 }
39 51
40 } // namespace extensions 52 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/feature_channel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698