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

Side by Side Diff: chrome/browser/chromeos/policy/system_log_uploader.cc

Issue 1875443003: Retry uploading in UploadJobImpl when error occurs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Threading checks, logging, test improvements Created 4 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 <utility> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "base/thread_task_runner_handle.h"
Andrew T Wilson (Slow) 2016/05/10 22:00:42 Is this include necessary still?
Marton Hunyady 2016/05/11 12:55:30 Done.
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/policy/upload_job_impl.h" 17 #include "chrome/browser/chromeos/policy/upload_job_impl.h"
17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 19 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "components/feedback/anonymizer_tool.h" 21 #include "components/feedback/anonymizer_tool.h"
21 #include "components/policy/core/browser/browser_policy_connector.h" 22 #include "components/policy/core/browser/browser_policy_connector.h"
22 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
23 #include "net/http/http_request_headers.h" 24 #include "net/http/http_request_headers.h"
24 #include "system_log_uploader.h" 25 #include "system_log_uploader.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 file_path, 58 file_path,
58 policy::SystemLogUploader::RemoveSensitiveData(&anonymizer, data))); 59 policy::SystemLogUploader::RemoveSensitiveData(&anonymizer, data)));
59 } 60 }
60 return system_logs; 61 return system_logs;
61 } 62 }
62 63
63 // An implementation of the |SystemLogUploader::Delegate|, that is used to 64 // An implementation of the |SystemLogUploader::Delegate|, that is used to
64 // create an upload job and load system logs from the disk. 65 // create an upload job and load system logs from the disk.
65 class SystemLogDelegate : public policy::SystemLogUploader::Delegate { 66 class SystemLogDelegate : public policy::SystemLogUploader::Delegate {
66 public: 67 public:
67 SystemLogDelegate(); 68 explicit SystemLogDelegate(
69 scoped_refptr<base::SequencedTaskRunner> task_runner);
68 ~SystemLogDelegate() override; 70 ~SystemLogDelegate() override;
69 71
70 // SystemLogUploader::Delegate: 72 // SystemLogUploader::Delegate:
71 void LoadSystemLogs(const LogUploadCallback& upload_callback) override; 73 void LoadSystemLogs(const LogUploadCallback& upload_callback) override;
72 74
73 std::unique_ptr<policy::UploadJob> CreateUploadJob( 75 std::unique_ptr<policy::UploadJob> CreateUploadJob(
74 const GURL& upload_url, 76 const GURL& upload_url,
75 policy::UploadJob::Delegate* delegate) override; 77 policy::UploadJob::Delegate* delegate) override;
76 78
77 private: 79 private:
80 // TaskRunner used for scheduling upload the upload task.
81 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
82
78 DISALLOW_COPY_AND_ASSIGN(SystemLogDelegate); 83 DISALLOW_COPY_AND_ASSIGN(SystemLogDelegate);
79 }; 84 };
80 85
81 SystemLogDelegate::SystemLogDelegate() {} 86 SystemLogDelegate::SystemLogDelegate(
87 scoped_refptr<base::SequencedTaskRunner> task_runner)
88 : task_runner_(task_runner) {}
82 89
83 SystemLogDelegate::~SystemLogDelegate() {} 90 SystemLogDelegate::~SystemLogDelegate() {}
84 91
85 void SystemLogDelegate::LoadSystemLogs( 92 void SystemLogDelegate::LoadSystemLogs(
86 const LogUploadCallback& upload_callback) { 93 const LogUploadCallback& upload_callback) {
87 // Run ReadFiles() in the thread that interacts with the file system and 94 // Run ReadFiles() in the thread that interacts with the file system and
88 // return system logs to |upload_callback| on the current thread. 95 // return system logs to |upload_callback| on the current thread.
89 base::PostTaskAndReplyWithResult(content::BrowserThread::GetBlockingPool(), 96 base::PostTaskAndReplyWithResult(content::BrowserThread::GetBlockingPool(),
90 FROM_HERE, base::Bind(&ReadFiles), 97 FROM_HERE, base::Bind(&ReadFiles),
91 upload_callback); 98 upload_callback);
92 } 99 }
93 100
94 std::unique_ptr<policy::UploadJob> SystemLogDelegate::CreateUploadJob( 101 std::unique_ptr<policy::UploadJob> SystemLogDelegate::CreateUploadJob(
95 const GURL& upload_url, 102 const GURL& upload_url,
96 policy::UploadJob::Delegate* delegate) { 103 policy::UploadJob::Delegate* delegate) {
97 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service = 104 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
98 chromeos::DeviceOAuth2TokenServiceFactory::Get(); 105 chromeos::DeviceOAuth2TokenServiceFactory::Get();
99 106
100 scoped_refptr<net::URLRequestContextGetter> system_request_context = 107 scoped_refptr<net::URLRequestContextGetter> system_request_context =
101 g_browser_process->system_request_context(); 108 g_browser_process->system_request_context();
102 std::string robot_account_id = 109 std::string robot_account_id =
103 device_oauth2_token_service->GetRobotAccountId(); 110 device_oauth2_token_service->GetRobotAccountId();
104 return std::unique_ptr<policy::UploadJob>(new policy::UploadJobImpl( 111 return std::unique_ptr<policy::UploadJob>(new policy::UploadJobImpl(
105 upload_url, robot_account_id, device_oauth2_token_service, 112 upload_url, robot_account_id, device_oauth2_token_service,
106 system_request_context, delegate, 113 system_request_context, delegate,
107 base::WrapUnique( 114 base::WrapUnique(new policy::UploadJobImpl::RandomMimeBoundaryGenerator),
108 new policy::UploadJobImpl::RandomMimeBoundaryGenerator))); 115 task_runner_));
109 } 116 }
110 117
111 // Returns the system log upload frequency. 118 // Returns the system log upload frequency.
112 base::TimeDelta GetUploadFrequency() { 119 base::TimeDelta GetUploadFrequency() {
113 base::TimeDelta upload_frequency(base::TimeDelta::FromMilliseconds( 120 base::TimeDelta upload_frequency(base::TimeDelta::FromMilliseconds(
114 policy::SystemLogUploader::kDefaultUploadDelayMs)); 121 policy::SystemLogUploader::kDefaultUploadDelayMs));
115 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 122 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
116 switches::kSystemLogUploadFrequency)) { 123 switches::kSystemLogUploadFrequency)) {
117 std::string string_value = 124 std::string string_value =
118 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 125 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 SystemLogUploader::SystemLogUploader( 165 SystemLogUploader::SystemLogUploader(
159 std::unique_ptr<Delegate> syslog_delegate, 166 std::unique_ptr<Delegate> syslog_delegate,
160 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 167 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
161 : retry_count_(0), 168 : retry_count_(0),
162 upload_frequency_(GetUploadFrequency()), 169 upload_frequency_(GetUploadFrequency()),
163 task_runner_(task_runner), 170 task_runner_(task_runner),
164 syslog_delegate_(std::move(syslog_delegate)), 171 syslog_delegate_(std::move(syslog_delegate)),
165 upload_enabled_(false), 172 upload_enabled_(false),
166 weak_factory_(this) { 173 weak_factory_(this) {
167 if (!syslog_delegate_) 174 if (!syslog_delegate_)
168 syslog_delegate_.reset(new SystemLogDelegate()); 175 syslog_delegate_.reset(new SystemLogDelegate(task_runner));
169 DCHECK(syslog_delegate_); 176 DCHECK(syslog_delegate_);
170 177
171 // Watch for policy changes. 178 // Watch for policy changes.
172 upload_enabled_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver( 179 upload_enabled_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver(
173 chromeos::kSystemLogUploadEnabled, 180 chromeos::kSystemLogUploadEnabled,
174 base::Bind(&SystemLogUploader::RefreshUploadSettings, 181 base::Bind(&SystemLogUploader::RefreshUploadSettings,
175 base::Unretained(this))); 182 base::Unretained(this)));
176 183
177 // Fetch the current value of the policy. 184 // Fetch the current value of the policy.
178 RefreshUploadSettings(); 185 RefreshUploadSettings();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 base::TimeDelta()); 293 base::TimeDelta());
287 // Ensure that we never have more than one pending delayed task. 294 // Ensure that we never have more than one pending delayed task.
288 weak_factory_.InvalidateWeakPtrs(); 295 weak_factory_.InvalidateWeakPtrs();
289 task_runner_->PostDelayedTask(FROM_HERE, 296 task_runner_->PostDelayedTask(FROM_HERE,
290 base::Bind(&SystemLogUploader::StartLogUpload, 297 base::Bind(&SystemLogUploader::StartLogUpload,
291 weak_factory_.GetWeakPtr()), 298 weak_factory_.GetWeakPtr()),
292 delay); 299 delay);
293 } 300 }
294 301
295 } // namespace policy 302 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698