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

Side by Side Diff: src/data_plan_provider.h

Issue 3528016: Cashew: implement backend usage API (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git
Patch Set: Fix code review nits and remove hardcoded usage URLs Created 10 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/data_plan.cc ('k') | src/data_plan_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium OS 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 SRC_DATA_PLAN_PROVIDER_H_
6 #define SRC_DATA_PLAN_PROVIDER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include <base/basictypes.h> // NOLINT
12 #include <base/scoped_ptr.h> // NOLINT
13 #include <base/values.h> // NOLINT
14
15 #include "src/http_fetcher.h"
16
17 namespace cashew {
18
19 class DataPlanProviderDelegate;
20
21 // carrier usage API proxy
22 class DataPlanProvider: public HttpFetcherDelegate {
23 public:
24 explicit DataPlanProvider(const std::string& carrier);
25 virtual ~DataPlanProvider();
26
27 // get cellular carrier for which this proxy is configured
28 virtual const std::string& GetCarrier() const;
29
30 // get usage API URL for which this proxy is configured
31 virtual const std::string& GetUsageUrl() const;
32
33 // set usage API URL for which this proxy is configured
34 virtual void SetUsageUrl(const std::string& usage_url);
35
36 // set delegate interface that will receive callbacks from this proxy
37 // it's ok to clear this by setting it to NULL
38 virtual void SetDelegate(DataPlanProviderDelegate *delegate);
39
40 // request that proxy obtain updated info from carrier API
41 // NOTES:
42 // - the request is asynchronous
43 // - the result will be returned via a callback to the delegate
44 // that has been set via SetDelegate
45 // - returns true on success and false on failure
46 // - success indicates only that a request to the API was initiated
47 // successfully, but it does not guarantee that the request will
48 // ultimately succeed
49 // - this call will fail if no valid url has been set via SetUsageUrl
50 // - this call will fail if no delegate has been set via SetDelegate
51 // - this call will return success and do nothing if an earlier
52 // request is already in progress
53 virtual bool RequestUsageUpdate();
54
55 // HttpFetcherDelegate methods
56
57 // transfer is progressing, we've received more bytes
58 virtual void ReceivedBytes(HttpFetcher *fetcher, const char *bytes,
59 int length);
60
61 // transfer has ended (either complete or aborted)
62 virtual void TransferComplete(HttpFetcher *fetcher, bool successful);
63
64 // cancel any pending requests that are in progress
65 void CancelPendingRequests();
66
67 private:
68 // cellular carrier
69 const std::string carrier_;
70
71 // usage API URL
72 std::string usage_url_;
73
74 // delegate
75 DataPlanProviderDelegate *delegate_;
76
77 // http fetcher
78 scoped_ptr<HttpFetcher> fetcher_;
79
80 // do we have an http request in progress?
81 bool request_in_progress_;
82
83 // stores response that we receive from usage API
84 std::vector<char> response_buffer_;
85
86 DISALLOW_COPY_AND_ASSIGN(DataPlanProvider);
87 };
88
89 // interface for delegates
90 class DataPlanProviderDelegate {
91 public:
92 virtual ~DataPlanProviderDelegate() {}
93
94 // Called when request has either completed successfully or failed.
95 // |parsed_usage_update| will be NULL if |successful| is false.
96 // Caller owns |parsed_usage_update| and will delete it after this
97 // callback returns, so delegate should copy anything it needs.
98 virtual void OnRequestComplete(const DataPlanProvider *provider,
99 bool successful,
100 const Value *parsed_usage_update) = 0;
101 };
102
103 } // namespace cashew
104
105 #endif // SRC_DATA_PLAN_PROVIDER_H_
OLDNEW
« no previous file with comments | « src/data_plan.cc ('k') | src/data_plan_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698