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

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: Remember the set channel also under scoped setter 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;
Devlin 2017/05/19 22:14:17 nit: \n
emaxx 2017/05/20 02:48:53 Done.
15 // The current channel overridden by |ScopedCurrentChannel|. The value is valid
16 // only whenever |g_channel_is_overridden| is true.
17 version_info::Channel g_overridden_channel = version_info::Channel::STABLE;
Devlin 2017/05/19 22:14:17 \n
emaxx 2017/05/20 02:48:53 Done.
18 // Whether an instance of |ScopedCurrentChannel| exists currently.
19 bool g_channel_is_overridden = false;
13 20
14 } // namespace 21 } // namespace
15 22
16 namespace extensions { 23 namespace extensions {
17 24
18 version_info::Channel GetCurrentChannel() { 25 version_info::Channel GetCurrentChannel() {
19 return g_current_channel; 26 return g_channel_is_overridden ? g_overridden_channel : g_current_channel;
20 } 27 }
21 28
22 void SetCurrentChannel(version_info::Channel channel) { 29 void SetCurrentChannel(version_info::Channel channel) {
23 g_current_channel = channel; 30 g_current_channel = channel;
24 } 31 }
25 32
26 version_info::Channel GetDefaultChannel() {
27 return kDefaultChannel;
28 }
29
30 ScopedCurrentChannel::ScopedCurrentChannel(version_info::Channel channel) 33 ScopedCurrentChannel::ScopedCurrentChannel(version_info::Channel channel)
31 : original_channel_(version_info::Channel::UNKNOWN) { 34 : channel_(channel),
32 original_channel_ = GetCurrentChannel(); 35 original_overridden_channel_(g_overridden_channel),
33 SetCurrentChannel(channel); 36 original_channel_is_overridden_(g_channel_is_overridden) {
37 g_overridden_channel = channel;
38 g_channel_is_overridden = true;
34 } 39 }
35 40
36 ScopedCurrentChannel::~ScopedCurrentChannel() { 41 ScopedCurrentChannel::~ScopedCurrentChannel() {
37 SetCurrentChannel(original_channel_); 42 DCHECK_EQ(g_overridden_channel, channel_)
43 << "Scoped channel setters are not nested properly";
Devlin 2017/05/19 22:14:17 One last bit of bikeshedding :) We could actually
emaxx 2017/05/20 02:48:53 Done.
44 g_overridden_channel = original_overridden_channel_;
45 g_channel_is_overridden = original_channel_is_overridden_;
38 } 46 }
39 47
40 } // namespace extensions 48 } // 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