OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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/weak_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 | |
18 namespace rappor { | |
19 | |
20 // Handles uploading logs to an external server. | |
21 class LogUploader : public net::URLFetcherDelegate { | |
22 public: | |
23 // Constructor takes the server_url that logs should be uploaded to, the | |
24 // mime_type of the uploaded data, and request context to create uploads | |
Ilya Sherman
2014/01/10 11:00:32
nit: "request context" -> "request_context"
Steven Holte
2014/01/14 00:47:54
Done.
| |
25 // with. | |
26 LogUploader(const char* server_url, const char* mime_type, | |
Ilya Sherman
2014/01/10 11:00:32
nit: Please pass "const std::string&" rather than
Steven Holte
2014/01/14 00:47:54
Done.
| |
27 net::URLRequestContextGetter* request_context); | |
Ilya Sherman
2014/01/10 11:00:32
nit: In header files, please wrap parameters so th
Steven Holte
2014/01/14 00:47:54
Done.
| |
28 | |
29 ~LogUploader(); | |
30 | |
31 // Adds an entry to the queue of logs to be uploaded to the server. | |
32 void QueueLog(const std::string& log); | |
33 | |
34 private: | |
35 // Starts transmission of the next log. | |
36 void StartScheduledUpload(); | |
37 | |
38 // Schedules a future call to StartScheduledUpload if one isn't already | |
39 // pending. | |
40 void ScheduleNextUpload(); | |
41 | |
42 // Increases the upload interval each time it's called, to handle the case | |
43 // where the server is having issues. | |
44 void BackOffUploadInterval(); | |
45 | |
46 // Implementation of net::URLFetcherDelegate. Called after transmission | |
47 // completes (either successfully or with failure). | |
48 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
49 | |
50 // Called when the upload is completed. | |
51 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); | |
52 | |
53 // The server URL to upload logs to. | |
54 const char* server_url_; | |
Ilya Sherman
2014/01/10 11:00:32
nit: This isn't const enough ;) If you want to st
Steven Holte
2014/01/14 00:47:54
changed to const std::string
| |
55 | |
56 // The mime type to specify on uploaded logs. | |
57 const char* mime_type_; | |
58 | |
59 net::URLRequestContextGetter* request_context_; | |
60 | |
61 // The outstanding transmission appears as a URL Fetch operation. | |
62 scoped_ptr<net::URLFetcher> current_fetch_; | |
63 | |
64 // The logs that still need to be uploaded. | |
65 std::queue<std::string> queued_logs_; | |
66 | |
67 base::OneShotTimer<LogUploader> upload_timer_; | |
68 | |
69 // Indicates that the last triggered upload hasn't resolved yet. | |
70 bool callback_pending_; | |
Ilya Sherman
2014/01/10 11:00:32
nit: I'd recommend adding a prefix like "has_" to
Steven Holte
2014/01/14 00:47:54
Done.
| |
71 | |
72 // The interval between being told an upload is done and starting the next | |
Ilya Sherman
2014/01/10 11:00:32
nit: "being told" -> "receiving confirmation" or s
Steven Holte
2014/01/14 00:47:54
Done.
| |
73 // upload. | |
74 base::TimeDelta upload_interval_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(LogUploader); | |
77 }; | |
Ilya Sherman
2014/01/10 11:00:32
How much of this code is fairly directly copied fr
Steven Holte
2014/01/14 00:47:54
Almost all of this code has some corresponding cod
| |
78 | |
79 } // namespace rappor | |
80 | |
81 #endif // COMPONENTS_RAPPOR_LOG_UPLOADER_H_ | |
OLD | NEW |