OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ |
6 #define CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ | 6 #define CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ |
7 | 7 |
8 #include "base/timer.h" | 8 #include "base/timer.h" |
9 #include "chrome/browser/profiles/profile_keyed_service.h" | 9 #include "chrome/browser/profiles/profile_keyed_service.h" |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // Gets new cards from the server and shows them as notifications. | 45 // Gets new cards from the server and shows them as notifications. |
46 void UpdateCards(); | 46 void UpdateCards(); |
47 | 47 |
48 // Schedules next cards update after the specified delay. | 48 // Schedules next cards update after the specified delay. |
49 void StartWaitingForNextUpdate(base::TimeDelta delay); | 49 void StartWaitingForNextUpdate(base::TimeDelta delay); |
50 void OnWaitingForNextUpdateEnds(); | 50 void OnWaitingForNextUpdateEnds(); |
51 | 51 |
52 // Starts obtaining location of the machine. | 52 // Starts obtaining location of the machine. |
53 void StartObtainingGeolocation(); | 53 void StartObtainingGeolocation(); |
54 void OnLocationObtained(const content::Geoposition& position); | 54 void OnLocationObtained(const content::Geoposition& position); |
| 55 void OnLocationRequestTimeout(); |
55 | 56 |
56 // Starts downloading cards from the server. | 57 // Starts downloading cards from the server. |
57 void StartServerRequest(const content::Geoposition& position); | 58 void StartServerRequest(const content::Geoposition& position); |
58 void OnServerRequestCompleted(net::URLRequest* request, int num_bytes); | 59 void OnServerRequestCompleted(net::URLRequest* request, int num_bytes); |
59 | 60 |
60 // Parses server response. Returns true if the parsing was successful. | 61 // Parses server response. Returns true if the parsing was successful. |
61 static bool ParseServerResponse(const net::URLRequest* request, | 62 static bool ParseServerResponse(const net::URLRequest* request, |
62 int num_bytes, | 63 int num_bytes, |
63 ServerResponse* server_response); | 64 ServerResponse* server_response); |
64 | 65 |
65 // Shows Google Now cards as notifications. | 66 // Shows Google Now cards as notifications. |
66 void ShowNotifications(const ServerResponse& server_response); | 67 void ShowNotifications(const ServerResponse& server_response); |
67 | 68 |
68 // The profile. | 69 // The profile. |
69 Profile* const profile_; | 70 Profile* const profile_; |
70 // Timer to schedule next cards update. | 71 // Timer to schedule next cards update. |
71 base::OneShotTimer<GoogleNowService> next_update_timer_; | 72 base::OneShotTimer<GoogleNowService> next_update_timer_; |
| 73 // Timer to cancel geolocation requests that take too long. |
| 74 base::OneShotTimer<GoogleNowService> geolocation_request_timer_; |
| 75 // Weak factory for the geolocation request callback. Used to ensure |
| 76 // geolocation request callback is not run after this object is destroyed. |
| 77 base::WeakPtrFactory<GoogleNowService> geolocation_request_weak_factory_; |
72 | 78 |
73 DISALLOW_COPY_AND_ASSIGN(GoogleNowService); | 79 DISALLOW_COPY_AND_ASSIGN(GoogleNowService); |
74 }; | 80 }; |
75 | 81 |
76 #endif // CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ | 82 #endif // CHROME_BROWSER_UI_GOOGLE_NOW_GOOGLE_NOW_SERVICE_H_ |
OLD | NEW |