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

Side by Side Diff: chrome/browser/chromeos/policy/upload_job_impl.h

Issue 1875443003: Retry uploading in UploadJobImpl when error occurs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Retry when token request failed, add backoff, add log messages Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ 6 #define CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 ~RandomMimeBoundaryGenerator() override; 47 ~RandomMimeBoundaryGenerator() override;
48 48
49 std::string GenerateBoundary() const override; // MimeBoundaryGenerator 49 std::string GenerateBoundary() const override; // MimeBoundaryGenerator
50 }; 50 };
51 51
52 UploadJobImpl(const GURL& upload_url, 52 UploadJobImpl(const GURL& upload_url,
53 const std::string& account_id, 53 const std::string& account_id,
54 OAuth2TokenService* token_service, 54 OAuth2TokenService* token_service,
55 scoped_refptr<net::URLRequestContextGetter> url_context_getter, 55 scoped_refptr<net::URLRequestContextGetter> url_context_getter,
56 Delegate* delegate, 56 Delegate* delegate,
57 std::unique_ptr<MimeBoundaryGenerator> boundary_generator); 57 std::unique_ptr<MimeBoundaryGenerator> boundary_generator,
58 const scoped_refptr<base::SequencedTaskRunner> task_runner);
Andrew T Wilson (Slow) 2016/05/02 09:15:49 Do you make any assumptions about this task_runner
Marton Hunyady 2016/05/04 11:26:41 Done.
58 ~UploadJobImpl() override; 59 ~UploadJobImpl() override;
59 60
60 // UploadJob: 61 // UploadJob:
61 void AddDataSegment(const std::string& name, 62 void AddDataSegment(const std::string& name,
62 const std::string& filename, 63 const std::string& filename,
63 const std::map<std::string, std::string>& header_entries, 64 const std::map<std::string, std::string>& header_entries,
64 std::unique_ptr<std::string> data) override; 65 std::unique_ptr<std::string> data) override;
65 void Start() override; 66 void Start() override;
66 67
67 private: 68 private:
68 // Indicates the current state of the UploadJobImpl. 69 // Indicates the current state of the UploadJobImpl.
70 // State transitions for successful upload:
71 // IDLE -> ACQUIRING_TOKEN -> PREPARING_CONTENT -> UPLOADING -> SUCCESS
72 // If error happens, state goes back to ACQUIRING_TOKEN.
73 // State transitions when error occurs once:
74 // IDLE -> ACQUIRING_TOKEN -> PREPARING_CONTENT -> UPLOADING ->
75 // -> ACQUIRING_TOKEN -> PREPARING_CONTENT -> UPLOADING -> SUCCESS
76 // State transitions when tried unsuccessfully kMaxRetries times:
77 // ... -> PREPARING_CONTENT -> UPLOADING -> ERROR
69 enum State { 78 enum State {
70 IDLE, // Start() has not been called. 79 IDLE, // Start() has not been called.
71 ACQUIRING_TOKEN, // Trying to acquire the access token. 80 ACQUIRING_TOKEN, // Trying to acquire the access token.
72 PREPARING_CONTENT, // Currently encoding the content. 81 PREPARING_CONTENT, // Currently encoding the content.
73 UPLOADING, // Upload started. 82 UPLOADING, // Upload started.
74 SUCCESS, // Upload successfully completed. 83 SUCCESS, // Upload successfully completed.
75 ERROR // Upload failed. 84 ERROR // Upload failed.
76 }; 85 };
77 86
78 // OAuth2TokenService::Consumer: 87 // OAuth2TokenService::Consumer:
79 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 88 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
80 const std::string& access_token, 89 const std::string& access_token,
81 const base::Time& expiration_time) override; 90 const base::Time& expiration_time) override;
82 void OnGetTokenFailure(const OAuth2TokenService::Request* request, 91 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
83 const GoogleServiceAuthError& error) override; 92 const GoogleServiceAuthError& error) override;
84 93
85 // net::URLFetcherDelegate: 94 // net::URLFetcherDelegate:
86 void OnURLFetchComplete(const net::URLFetcher* source) override; 95 void OnURLFetchComplete(const net::URLFetcher* source) override;
87 96
97 void HandleError(ErrorCode errorCode);
98
88 // Requests an access token for the upload scope. 99 // Requests an access token for the upload scope.
89 void RequestAccessToken(); 100 void RequestAccessToken();
90 101
91 // Dispatches POST request to URLFetcher. 102 // Dispatches POST request to URLFetcher.
92 void StartUpload(const std::string& access_token); 103 void StartUpload();
93 104
94 // Constructs the body of the POST request by concatenating the 105 // Constructs the body of the POST request by concatenating the
95 // |data_segments_|, separated by appropriate content-disposition headers and 106 // |data_segments_|, separated by appropriate content-disposition headers and
96 // a MIME boundary. Places the request body in |post_data_| and a copy of the 107 // a MIME boundary. Places the request body in |post_data_| and a copy of the
97 // MIME boundary in |mime_boundary_|. Returns true on success. If |post_data_| 108 // MIME boundary in |mime_boundary_|. Returns true on success. If |post_data_|
98 // and |mime_boundary_| were set already, returns true immediately. In case of 109 // and |mime_boundary_| were set already, returns true immediately. In case of
99 // an error, clears |post_data_| and |mime_boundary_| and returns false. 110 // an error, clears |post_data_| and |mime_boundary_| and returns false.
100 bool SetUpMultipart(); 111 bool SetUpMultipart();
101 112
102 // Assembles the request and starts the URLFetcher. Fails if another upload 113 // Assembles the request and starts the URLFetcher. Fails if another upload
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 151
141 // The OAuth access token. 152 // The OAuth access token.
142 std::string access_token_; 153 std::string access_token_;
143 154
144 // Helper to upload the data. 155 // Helper to upload the data.
145 std::unique_ptr<net::URLFetcher> upload_fetcher_; 156 std::unique_ptr<net::URLFetcher> upload_fetcher_;
146 157
147 // The data chunks to be uploaded. 158 // The data chunks to be uploaded.
148 ScopedVector<DataSegment> data_segments_; 159 ScopedVector<DataSegment> data_segments_;
149 160
161 // TaskRunner used for scheduling retry attempts.
162 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
163
164 // Should remain the last member so it will be destroyed first and
165 // invalidate all weak pointers.
166 base::WeakPtrFactory<UploadJobImpl> weak_factory_;
167
150 DISALLOW_COPY_AND_ASSIGN(UploadJobImpl); 168 DISALLOW_COPY_AND_ASSIGN(UploadJobImpl);
151 }; 169 };
152 170
153 } // namespace policy 171 } // namespace policy
154 172
155 #endif // CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ 173 #endif // CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698