[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / component_updater / component_updater_command_line_config_policy.cc
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/component_updater/component_updater_command_line_config_policy.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/command_line.h"
11 #include "base/containers/contains.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/sys_string_conversions.h"
15 #include "build/build_config.h"
16 #include "components/component_updater/component_updater_switches.h"
17
18 namespace component_updater {
19
20 namespace {
21
22 // Debug values you can pass to --component-updater=value1,value2. Do not
23 // use these values in production code.
24
25 // Speed up the initial component checking.
26 const char kSwitchFastUpdate[] = "fast-update";
27
28 // Disables pings. Pings are the requests sent to the update server that report
29 // the success or the failure of component install or update attempts.
30 const char kSwitchDisablePings[] = "disable-pings";
31
32 // Sets the URL for updates.
33 const char kSwitchUrlSource[] = "url-source";
34
35 // Disables differential updates.
36 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates";
37
38 // Configures the initial delay before the first component update check. The
39 // value is in seconds.
40 const char kInitialDelay[] = "initial-delay";
41
42 #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
43 // Disables background downloads.
44 const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads";
45 #endif  // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
46
47 // If there is an element of |vec| of the form |test|=.*, returns the right-
48 // hand side of that assignment. Otherwise, returns an empty string.
49 // The right-hand side may contain additional '=' characters, allowing for
50 // further nesting of switch arguments.
51 std::string GetSwitchArgument(const std::vector<std::string>& vec,
52                               const char* test) {
53   if (vec.empty()) {
54     return std::string();
55   }
56   for (auto it = vec.begin(); it != vec.end(); ++it) {
57     const std::size_t found = it->find("=");
58     if (found != std::string::npos) {
59       if (it->substr(0, found) == test) {
60         return it->substr(found + 1);
61       }
62     }
63   }
64   return std::string();
65 }
66
67 }  // namespace
68
69 // Add "testrequest=1" attribute to the update check request.
70 const char kSwitchTestRequestParam[] = "test-request";
71
72 ComponentUpdaterCommandLineConfigPolicy::
73     ComponentUpdaterCommandLineConfigPolicy(const base::CommandLine* cmdline) {
74   DCHECK(cmdline);
75   // Parse comma-delimited debug flags.
76   std::vector<std::string> switch_values = base::SplitString(
77       cmdline->GetSwitchValueASCII(switches::kComponentUpdater), ",",
78       base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
79
80 #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
81   background_downloads_enabled_ =
82       !base::Contains(switch_values, kSwitchDisableBackgroundDownloads);
83 #else
84   background_downloads_enabled_ = false;
85 #endif
86
87   deltas_enabled_ = !base::Contains(switch_values, kSwitchDisableDeltaUpdates);
88   fast_update_ = base::Contains(switch_values, kSwitchFastUpdate);
89   pings_enabled_ = !base::Contains(switch_values, kSwitchDisablePings);
90   test_request_ = base::Contains(switch_values, kSwitchTestRequestParam);
91
92   const std::string switch_url_source =
93       GetSwitchArgument(switch_values, kSwitchUrlSource);
94   if (!switch_url_source.empty()) {
95     url_source_override_ = GURL(switch_url_source);
96     DCHECK(url_source_override_.is_valid());
97   }
98
99   const std::string initial_delay =
100       GetSwitchArgument(switch_values, kInitialDelay);
101   double initial_delay_seconds = 0;
102   if (base::StringToDouble(initial_delay, &initial_delay_seconds)) {
103     initial_delay_ = base::Seconds(initial_delay_seconds);
104   }
105 }
106
107 bool ComponentUpdaterCommandLineConfigPolicy::BackgroundDownloadsEnabled()
108     const {
109   return background_downloads_enabled_;
110 }
111
112 bool ComponentUpdaterCommandLineConfigPolicy::DeltaUpdatesEnabled() const {
113   return deltas_enabled_;
114 }
115
116 bool ComponentUpdaterCommandLineConfigPolicy::FastUpdate() const {
117   return fast_update_;
118 }
119
120 bool ComponentUpdaterCommandLineConfigPolicy::PingsEnabled() const {
121   return pings_enabled_;
122 }
123
124 bool ComponentUpdaterCommandLineConfigPolicy::TestRequest() const {
125   return test_request_;
126 }
127
128 GURL ComponentUpdaterCommandLineConfigPolicy::UrlSourceOverride() const {
129   return url_source_override_;
130 }
131
132 base::TimeDelta ComponentUpdaterCommandLineConfigPolicy::InitialDelay() const {
133   return initial_delay_;
134 }
135
136 }  // namespace component_updater