OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_RAPPOR_LOG_UPLOADER_H_ | |
6 #define COMPONENTS_RAPPOR_LOG_UPLOADER_H_ | |
7 | |
8 #include <queue> | |
9 #include <string> | |
10 | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/time/time.h" | |
13 #include "base/timer/timer.h" | |
14 #include "net/url_request/url_fetcher.h" | |
15 #include "net/url_request/url_fetcher_delegate.h" | |
16 #include "net/url_request/url_request_context_getter.h" | |
17 #include "url/gurl.h" | |
18 | |
19 namespace rappor { | |
20 | |
21 // Handles uploading logs to an external server. | |
22 class LogUploader : public net::URLFetcherDelegate { | |
23 public: | |
24 // Constructor takes the server_url that logs should be uploaded to, the | |
25 // mime_type of the uploaded data, and request_context to create uploads | |
26 // with. | |
27 LogUploader(const GURL& server_url, | |
28 const std::string& mime_type, | |
29 net::URLRequestContextGetter* request_context); | |
30 | |
31 ~LogUploader(); | |
32 | |
33 // Adds an entry to the queue of logs to be uploaded to the server. | |
Alexei Svitkine (slow)
2014/02/05 18:07:01
Mention that |log| is the serialized proto bytes (
Steven Holte
2014/02/05 22:44:37
Changed text to:
// Adds an entry to the queue o
| |
34 void QueueLog(const std::string& log); | |
35 | |
36 private: | |
37 // Starts transmission of the next log. | |
38 void StartScheduledUpload(); | |
39 | |
40 // Schedules a future call to StartScheduledUpload if one isn't already | |
41 // pending. | |
42 void ScheduleNextUpload(); | |
43 | |
44 // Increases the upload interval each time it's called, to handle the case | |
45 // where the server is having issues. | |
46 void BackOffUploadInterval(); | |
47 | |
48 // Implementation of net::URLFetcherDelegate. Called after transmission | |
49 // completes (either successfully or with failure). | |
50 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
51 | |
52 // Called when the upload is completed. | |
53 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); | |
54 | |
55 // The server URL to upload logs to. | |
56 const GURL server_url_; | |
57 | |
58 // The mime type to specify on uploaded logs. | |
59 const std::string mime_type_; | |
60 | |
61 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
62 | |
63 // The outstanding transmission appears as a URL Fetch operation. | |
64 scoped_ptr<net::URLFetcher> current_fetch_; | |
65 | |
66 // The logs that still need to be uploaded. | |
67 std::queue<std::string> queued_logs_; | |
68 | |
69 base::OneShotTimer<LogUploader> upload_timer_; | |
70 | |
71 // Indicates that the last triggered upload hasn't resolved yet. | |
72 bool has_callback_pending_; | |
73 | |
74 // The interval to wait after an upload's URLFetcher completion before | |
75 // starting the next upload attempt. | |
76 base::TimeDelta upload_interval_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(LogUploader); | |
79 }; | |
80 | |
81 } // namespace rappor | |
82 | |
83 #endif // COMPONENTS_RAPPOR_LOG_UPLOADER_H_ | |
OLD | NEW |