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 LogUploader(const char* server_url, const char* mime_type); | |
Alexei Svitkine (slow)
2014/01/09 19:23:09
Document params. Add explicit destructor, define i
Steven Holte
2014/01/09 22:03:01
Done.
| |
24 | |
25 void SetRequestContext(net::URLRequestContextGetter* request_context); | |
Alexei Svitkine (slow)
2014/01/09 19:23:09
Any reason this shouldn't be a ctor param?
Steven Holte
2014/01/09 22:03:01
Done.
| |
26 | |
27 void QueueLog(const std::string& logData); | |
Alexei Svitkine (slow)
2014/01/09 19:23:09
log_data. Also, document these.
Steven Holte
2014/01/09 22:03:01
Done.
| |
28 | |
29 private: | |
30 // Starts transmission of the next log. | |
31 void StartScheduledUpload(); | |
32 | |
33 // Schedules a future call to StartScheduledUpload if one isn't already | |
34 // pending. | |
35 void ScheduleNextUpload(); | |
36 | |
37 // Increases the upload interval each time it's called, to handle the case | |
38 // where the server is having issues. | |
39 void BackOffUploadInterval(); | |
40 | |
41 // Implementation of net::URLFetcherDelegate. Called after transmission | |
42 // completes (either successfully or with failure). | |
43 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
44 | |
45 // Called when the upload is completed. | |
46 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); | |
47 | |
48 // The server URL to upload logs to. | |
49 const char* server_url_; | |
50 | |
51 // The mime type to specify on uploaded logs. | |
52 const char* mime_type_; | |
53 | |
54 net::URLRequestContextGetter* request_context_; | |
55 | |
56 // The outstanding transmission appears as a URL Fetch operation. | |
57 scoped_ptr<net::URLFetcher> current_fetch_; | |
58 | |
59 // The logs that still need to be uploaded. | |
60 std::queue<std::string> queued_logs_; | |
61 | |
62 base::OneShotTimer<LogUploader> upload_timer_; | |
63 | |
64 // Indicates that the last triggered upload hasn't resolved yet. | |
65 bool callback_pending_; | |
66 | |
67 // The interval between being told an upload is done and starting the next | |
68 // upload. | |
69 base::TimeDelta upload_interval_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(LogUploader); | |
72 }; | |
73 | |
74 } // namespace rappor | |
75 | |
76 #endif // COMPONENTS_RAPPOR_LOG_UPLOADER_H_ | |
OLD | NEW |