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

Side by Side Diff: chromeos/system/statistics_provider.cc

Issue 2958353002: [Cleanup] Migrate the StatisticsProvider to use the TaskScheduler (Closed)
Patch Set: rewrap a line Created 3 years, 5 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 | « chromeos/system/statistics_provider.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 "chromeos/system/statistics_provider.h" 5 #include "chromeos/system/statistics_provider.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/containers/flat_map.h" 11 #include "base/containers/flat_map.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/json/json_file_value_serializer.h" 14 #include "base/json/json_file_value_serializer.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/synchronization/cancellation_flag.h" 22 #include "base/synchronization/cancellation_flag.h"
23 #include "base/synchronization/waitable_event.h" 23 #include "base/synchronization/waitable_event.h"
24 #include "base/sys_info.h" 24 #include "base/sys_info.h"
25 #include "base/task_runner.h" 25 #include "base/task_runner.h"
26 #include "base/task_scheduler/post_task.h"
27 #include "base/task_scheduler/task_traits.h"
26 #include "base/threading/thread_restrictions.h" 28 #include "base/threading/thread_restrictions.h"
27 #include "base/time/time.h" 29 #include "base/time/time.h"
28 #include "base/values.h" 30 #include "base/values.h"
29 #include "chromeos/app_mode/kiosk_oem_manifest_parser.h" 31 #include "chromeos/app_mode/kiosk_oem_manifest_parser.h"
30 #include "chromeos/chromeos_constants.h" 32 #include "chromeos/chromeos_constants.h"
31 #include "chromeos/chromeos_paths.h" 33 #include "chromeos/chromeos_paths.h"
32 #include "chromeos/chromeos_switches.h" 34 #include "chromeos/chromeos_switches.h"
33 #include "chromeos/system/name_value_pairs_parser.h" 35 #include "chromeos/system/name_value_pairs_parser.h"
34 36
35 namespace chromeos { 37 namespace chromeos {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 const char kOemKeyboardDrivenOobeKey[] = "oem_keyboard_driven_oobe"; 203 const char kOemKeyboardDrivenOobeKey[] = "oem_keyboard_driven_oobe";
202 204
203 bool HasOemPrefix(const std::string& name) { 205 bool HasOemPrefix(const std::string& name) {
204 return name.substr(0, 4) == "oem_"; 206 return name.substr(0, 4) == "oem_";
205 } 207 }
206 208
207 // The StatisticsProvider implementation used in production. 209 // The StatisticsProvider implementation used in production.
208 class StatisticsProviderImpl : public StatisticsProvider { 210 class StatisticsProviderImpl : public StatisticsProvider {
209 public: 211 public:
210 // StatisticsProvider implementation: 212 // StatisticsProvider implementation:
211 void StartLoadingMachineStatistics( 213 void StartLoadingMachineStatistics(bool load_oem_manifest) override;
212 const scoped_refptr<base::TaskRunner>& file_task_runner,
213 bool load_oem_manifest) override;
214 bool GetMachineStatistic(const std::string& name, 214 bool GetMachineStatistic(const std::string& name,
215 std::string* result) override; 215 std::string* result) override;
216 bool GetMachineFlag(const std::string& name, bool* result) override; 216 bool GetMachineFlag(const std::string& name, bool* result) override;
217 void Shutdown() override; 217 void Shutdown() override;
218 218
219 // Returns true when Chrome OS is running in a VM. NOTE: if crossystem is not 219 // Returns true when Chrome OS is running in a VM. NOTE: if crossystem is not
220 // installed it will return false even if Chrome OS is running in a VM. 220 // installed it will return false even if Chrome OS is running in a VM.
221 bool IsRunningOnVm() override; 221 bool IsRunningOnVm() override;
222 222
223 static StatisticsProviderImpl* GetInstance(); 223 static StatisticsProviderImpl* GetInstance();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 regional_data_extractors_[kKeyboardLayoutKey] = 420 regional_data_extractors_[kKeyboardLayoutKey] =
421 &GetKeyboardLayoutFromRegionalData; 421 &GetKeyboardLayoutFromRegionalData;
422 regional_data_extractors_[kInitialTimezoneKey] = 422 regional_data_extractors_[kInitialTimezoneKey] =
423 &GetInitialTimezoneFromRegionalData; 423 &GetInitialTimezoneFromRegionalData;
424 } 424 }
425 425
426 StatisticsProviderImpl::~StatisticsProviderImpl() { 426 StatisticsProviderImpl::~StatisticsProviderImpl() {
427 } 427 }
428 428
429 void StatisticsProviderImpl::StartLoadingMachineStatistics( 429 void StatisticsProviderImpl::StartLoadingMachineStatistics(
430 const scoped_refptr<base::TaskRunner>& file_task_runner,
431 bool load_oem_manifest) { 430 bool load_oem_manifest) {
432 CHECK(!load_statistics_started_); 431 CHECK(!load_statistics_started_);
433 load_statistics_started_ = true; 432 load_statistics_started_ = true;
434 433
435 VLOG(1) << "Started loading statistics. Load OEM Manifest: " 434 VLOG(1) << "Started loading statistics. Load OEM Manifest: "
436 << load_oem_manifest; 435 << load_oem_manifest;
437 436
438 file_task_runner->PostTask( 437 base::PostTaskWithTraits(
439 FROM_HERE, 438 FROM_HERE,
440 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, 439 {base::MayBlock(), base::TaskPriority::BACKGROUND,
441 base::Unretained(this), 440 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
442 load_oem_manifest)); 441 base::BindOnce(&StatisticsProviderImpl::LoadMachineStatistics,
442 base::Unretained(this), load_oem_manifest));
443 } 443 }
444 444
445 void StatisticsProviderImpl::LoadMachineStatistics(bool load_oem_manifest) { 445 void StatisticsProviderImpl::LoadMachineStatistics(bool load_oem_manifest) {
446 // Run from the file task runner. StatisticsProviderImpl is a Singleton<> and 446 // Run from the file task runner. StatisticsProviderImpl is a Singleton<> and
447 // will not be destroyed until after threads have been stopped, so this test 447 // will not be destroyed until after threads have been stopped, so this test
448 // is always safe. 448 // is always safe.
449 if (cancellation_flag_.IsSet()) 449 if (cancellation_flag_.IsSet())
450 return; 450 return;
451 451
452 NameValuePairsParser parser(&machine_info_); 452 NameValuePairsParser parser(&machine_info_);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 return StatisticsProviderImpl::GetInstance(); 627 return StatisticsProviderImpl::GetInstance();
628 } 628 }
629 629
630 // static 630 // static
631 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) { 631 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) {
632 g_test_statistics_provider = test_provider; 632 g_test_statistics_provider = test_provider;
633 } 633 }
634 634
635 } // namespace system 635 } // namespace system
636 } // namespace chromeos 636 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/system/statistics_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698