Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ios / chrome / browser / ui / commands / set_up_for_testing_command.mm
bloba24c1c60980e9b9c2691d2be984db5fd6e42f119
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "ios/chrome/browser/ui/commands/set_up_for_testing_command.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
10 #include "net/base/url_util.h"
11 #include "url/gurl.h"
13 namespace {
14 // Clear all browsing data.
15 const char kClearBrowsingData[] = "clearBrowsingData";
16 // Close existing tabs.
17 const char kCloseTabs[] = "closeTabs";
18 // Number of new tabs.
19 const char kNumberOfNewTabs[] = "numberOfNewTabs";
20 }  // namespace
22 @implementation SetUpForTestingCommand
24 @synthesize clearBrowsingData = _clearBrowsingData;
25 @synthesize closeTabs = _closeTabs;
26 @synthesize numberOfNewTabs = _numberOfNewTabs;
28 - (instancetype)initWithTag:(NSInteger)tag {
29   NOTREACHED();
30   return nil;
33 - (instancetype)initWithURL:(const GURL&)url {
34   std::string value;
35   int numberOfNewTabs = 0;
36   if (net::GetValueForKeyInQuery(url, kNumberOfNewTabs, &value)) {
37     if (!base::StringToInt(value, &numberOfNewTabs) || numberOfNewTabs < 0) {
38       // Ignore incorrect value for "numberOfNewTabs".
39       numberOfNewTabs = 0;
40     }
41   }
42   std::string ignored;
43   bool clearBrowsingData =
44       net::GetValueForKeyInQuery(url, kClearBrowsingData, &ignored);
45   bool closeTabs = net::GetValueForKeyInQuery(url, kCloseTabs, &ignored);
46   return [self initWithClearBrowsingData:clearBrowsingData
47                                closeTabs:closeTabs
48                          numberOfNewTabs:numberOfNewTabs];
51 - (instancetype)initWithClearBrowsingData:(BOOL)clearBrowsingData
52                                 closeTabs:(BOOL)closeTabs
53                           numberOfNewTabs:(NSInteger)numberOfNewTabs {
54   self = [super initWithTag:IDC_SETUP_FOR_TESTING];
55   if (self) {
56     _clearBrowsingData = clearBrowsingData;
57     _closeTabs = closeTabs;
58     _numberOfNewTabs = numberOfNewTabs;
59   }
60   return self;
63 @end