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

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: Remove unused include 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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 file_path, 57 file_path,
58 policy::SystemLogUploader::RemoveSensitiveData(&anonymizer, data))); 58 policy::SystemLogUploader::RemoveSensitiveData(&anonymizer, data)));
59 } 59 }
60 return system_logs; 60 return system_logs;
61 } 61 }
62 62
63 // An implementation of the |SystemLogUploader::Delegate|, that is used to 63 // An implementation of the |SystemLogUploader::Delegate|, that is used to
64 // create an upload job and load system logs from the disk. 64 // create an upload job and load system logs from the disk.
65 class SystemLogDelegate : public policy::SystemLogUploader::Delegate { 65 class SystemLogDelegate : public policy::SystemLogUploader::Delegate {
66 public: 66 public:
67 SystemLogDelegate(); 67 explicit SystemLogDelegate(
68 scoped_refptr<base::SequencedTaskRunner> task_runner);
68 ~SystemLogDelegate() override; 69 ~SystemLogDelegate() override;
69 70
70 // SystemLogUploader::Delegate: 71 // SystemLogUploader::Delegate:
71 void LoadSystemLogs(const LogUploadCallback& upload_callback) override; 72 void LoadSystemLogs(const LogUploadCallback& upload_callback) override;
72 73
73 std::unique_ptr<policy::UploadJob> CreateUploadJob( 74 std::unique_ptr<policy::UploadJob> CreateUploadJob(
74 const GURL& upload_url, 75 const GURL& upload_url,
75 policy::UploadJob::Delegate* delegate) override; 76 policy::UploadJob::Delegate* delegate) override;
76 77
77 private: 78 private:
79 // TaskRunner used for scheduling upload the upload task.
80 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
81
78 DISALLOW_COPY_AND_ASSIGN(SystemLogDelegate); 82 DISALLOW_COPY_AND_ASSIGN(SystemLogDelegate);
79 }; 83 };
80 84
81 SystemLogDelegate::SystemLogDelegate() {} 85 SystemLogDelegate::SystemLogDelegate(
86 scoped_refptr<base::SequencedTaskRunner> task_runner)
87 : task_runner_(task_runner) {}
82 88
83 SystemLogDelegate::~SystemLogDelegate() {} 89 SystemLogDelegate::~SystemLogDelegate() {}
84 90
85 void SystemLogDelegate::LoadSystemLogs( 91 void SystemLogDelegate::LoadSystemLogs(
86 const LogUploadCallback& upload_callback) { 92 const LogUploadCallback& upload_callback) {
87 // Run ReadFiles() in the thread that interacts with the file system and 93 // Run ReadFiles() in the thread that interacts with the file system and
88 // return system logs to |upload_callback| on the current thread. 94 // return system logs to |upload_callback| on the current thread.
89 base::PostTaskAndReplyWithResult(content::BrowserThread::GetBlockingPool(), 95 base::PostTaskAndReplyWithResult(content::BrowserThread::GetBlockingPool(),
90 FROM_HERE, base::Bind(&ReadFiles), 96 FROM_HERE, base::Bind(&ReadFiles),
91 upload_callback); 97 upload_callback);
92 } 98 }
93 99
94 std::unique_ptr<policy::UploadJob> SystemLogDelegate::CreateUploadJob( 100 std::unique_ptr<policy::UploadJob> SystemLogDelegate::CreateUploadJob(
95 const GURL& upload_url, 101 const GURL& upload_url,
96 policy::UploadJob::Delegate* delegate) { 102 policy::UploadJob::Delegate* delegate) {
97 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service = 103 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
98 chromeos::DeviceOAuth2TokenServiceFactory::Get(); 104 chromeos::DeviceOAuth2TokenServiceFactory::Get();
99 105
100 scoped_refptr<net::URLRequestContextGetter> system_request_context = 106 scoped_refptr<net::URLRequestContextGetter> system_request_context =
101 g_browser_process->system_request_context(); 107 g_browser_process->system_request_context();
102 std::string robot_account_id = 108 std::string robot_account_id =
103 device_oauth2_token_service->GetRobotAccountId(); 109 device_oauth2_token_service->GetRobotAccountId();
104 return std::unique_ptr<policy::UploadJob>(new policy::UploadJobImpl( 110 return std::unique_ptr<policy::UploadJob>(new policy::UploadJobImpl(
105 upload_url, robot_account_id, device_oauth2_token_service, 111 upload_url, robot_account_id, device_oauth2_token_service,
106 system_request_context, delegate, 112 system_request_context, delegate,
107 base::WrapUnique( 113 base::WrapUnique(new policy::UploadJobImpl::RandomMimeBoundaryGenerator),
108 new policy::UploadJobImpl::RandomMimeBoundaryGenerator))); 114 task_runner_));
Andrew T Wilson (Slow) 2016/05/18 11:59:38 This line I think is mis-indented.
Marton Hunyady 2016/05/18 12:27:03 task_runner_ belongs to the same level as everythi
Andrew T Wilson (Slow) 2016/05/18 13:10:46 You are right, I misread it :)
109 } 115 }
110 116
111 // Returns the system log upload frequency. 117 // Returns the system log upload frequency.
112 base::TimeDelta GetUploadFrequency() { 118 base::TimeDelta GetUploadFrequency() {
113 base::TimeDelta upload_frequency(base::TimeDelta::FromMilliseconds( 119 base::TimeDelta upload_frequency(base::TimeDelta::FromMilliseconds(
114 policy::SystemLogUploader::kDefaultUploadDelayMs)); 120 policy::SystemLogUploader::kDefaultUploadDelayMs));
115 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 121 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
116 switches::kSystemLogUploadFrequency)) { 122 switches::kSystemLogUploadFrequency)) {
117 std::string string_value = 123 std::string string_value =
118 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 124 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 SystemLogUploader::SystemLogUploader( 164 SystemLogUploader::SystemLogUploader(
159 std::unique_ptr<Delegate> syslog_delegate, 165 std::unique_ptr<Delegate> syslog_delegate,
160 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 166 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
161 : retry_count_(0), 167 : retry_count_(0),
162 upload_frequency_(GetUploadFrequency()), 168 upload_frequency_(GetUploadFrequency()),
163 task_runner_(task_runner), 169 task_runner_(task_runner),
164 syslog_delegate_(std::move(syslog_delegate)), 170 syslog_delegate_(std::move(syslog_delegate)),
165 upload_enabled_(false), 171 upload_enabled_(false),
166 weak_factory_(this) { 172 weak_factory_(this) {
167 if (!syslog_delegate_) 173 if (!syslog_delegate_)
168 syslog_delegate_.reset(new SystemLogDelegate()); 174 syslog_delegate_.reset(new SystemLogDelegate(task_runner));
169 DCHECK(syslog_delegate_); 175 DCHECK(syslog_delegate_);
170 176
171 // Watch for policy changes. 177 // Watch for policy changes.
172 upload_enabled_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver( 178 upload_enabled_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver(
173 chromeos::kSystemLogUploadEnabled, 179 chromeos::kSystemLogUploadEnabled,
174 base::Bind(&SystemLogUploader::RefreshUploadSettings, 180 base::Bind(&SystemLogUploader::RefreshUploadSettings,
175 base::Unretained(this))); 181 base::Unretained(this)));
176 182
177 // Fetch the current value of the policy. 183 // Fetch the current value of the policy.
178 RefreshUploadSettings(); 184 RefreshUploadSettings();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 base::TimeDelta()); 292 base::TimeDelta());
287 // Ensure that we never have more than one pending delayed task. 293 // Ensure that we never have more than one pending delayed task.
288 weak_factory_.InvalidateWeakPtrs(); 294 weak_factory_.InvalidateWeakPtrs();
289 task_runner_->PostDelayedTask(FROM_HERE, 295 task_runner_->PostDelayedTask(FROM_HERE,
290 base::Bind(&SystemLogUploader::StartLogUpload, 296 base::Bind(&SystemLogUploader::StartLogUpload,
291 weak_factory_.GetWeakPtr()), 297 weak_factory_.GetWeakPtr()),
292 delay); 298 delay);
293 } 299 }
294 300
295 } // namespace policy 301 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698