OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ | |
6 #define CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ | |
7 | |
8 #include "base/timer.h" | |
9 #include "chrome/browser/profiles/profile_keyed_service.h" | |
10 | |
11 class Profile; | |
12 | |
13 namespace content { | |
14 struct Geoposition; | |
15 } | |
16 | |
17 namespace net { | |
18 class URLRequest; | |
19 } | |
20 | |
21 // The Google Now service gets Google Now cards from the server and shows them | |
22 // as Chrome notifications. | |
23 // The service performs periodic updating of Google Now cards. | |
24 // Each updating of the cards consists of 3 steps: | |
25 // 1. Obtaining the location of the machine (asynchronous); | |
26 // 2. Making a server request (asynchronous); | |
27 // 3. Showing the cards as notifications. | |
28 class GoogleNowService : public ProfileKeyedService { | |
29 public: | |
30 // Must call Init after construction. | |
31 explicit GoogleNowService(Profile* profile); | |
32 virtual ~GoogleNowService(); | |
33 void Init(); | |
34 | |
35 private: | |
36 // Parsed response from the server. | |
37 struct ServerResponse; | |
38 | |
39 // Returns true if Google Now integration is enabled for the profile. | |
40 bool IsGoogleNowEnabled() const; | |
41 // Gets new cards from the server and shows them as notifications. | |
42 void UpdateCards(); | |
43 | |
44 // Schedules next cards update after the specified delay. | |
45 void StartWaitingForNextUpdate(int64 delay_ms); | |
46 void OnWaitingForNextUpdateEnds(); | |
47 | |
48 // Starts obtaining location of the machine. | |
49 void StartObtainingGeolocation(); | |
50 void OnLocationObtained(const content::Geoposition& position); | |
51 | |
52 // Starts downloading cards from the server. | |
53 void StartServerRequest(const content::Geoposition& position); | |
54 void OnServerRequestCompleted(net::URLRequest* request, int num_bytes); | |
55 | |
56 // Parses server response. Returns true if the parsing was successful. | |
57 static bool ParseServerResponse(const net::URLRequest* request, int num_bytes, | |
sky
2012/12/06 16:40:54
nit: each param on its own line.
vadimt
2012/12/06 20:43:16
Done.
| |
58 ServerResponse* server_response); | |
59 | |
60 // Shows Google Now cards as notifications. | |
61 void ShowNotifications(const ServerResponse& server_response); | |
62 | |
63 // The profile. | |
64 Profile* const profile_; | |
65 // Timer to schedule next cards update. | |
66 base::OneShotTimer<GoogleNowService> next_update_timer_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(GoogleNowService); | |
69 }; | |
70 | |
71 #endif // CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ | |
OLD | NEW |