1 // Copyright 2014 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_CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_ 6 #define CHROME_BROWSER_CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_ 7 8 #include "base/macros.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_vector.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/threading/thread_checker.h" 14 #include "base/time/time.h" 15 #include "chrome/browser/chromeos/timezone/timezone_request.h" 16 #include "url/gurl.h" 17 18 namespace net { 19 class URLRequestContextGetter; 20 } 21 22 namespace chromeos { 23 24 struct Geoposition; 25 26 // This class implements Google TimeZone API. 27 // 28 // Note: this should probably be a singleton to monitor requests rate. 29 // But as it is used only from WizardController, it can be owned by it for now. 30 class TimeZoneProvider { 31 public: 32 TimeZoneProvider(net::URLRequestContextGetter* url_context_getter, 33 const GURL& url); 34 virtual ~TimeZoneProvider(); 35 36 // Initiates new request (See TimeZoneRequest for parameters description.) 37 void RequestTimezone(const Geoposition& position, 38 bool sensor, 39 base::TimeDelta timeout, 40 TimeZoneRequest::TimeZoneResponseCallback callback); 41 42 private: 43 friend class TestTimeZoneAPIURLFetcherCallback; 44 45 // Deletes request from requests_. 46 void OnTimezoneResponse(TimeZoneRequest* request, 47 TimeZoneRequest::TimeZoneResponseCallback callback, 48 scoped_ptr<TimeZoneResponseData> timezone, 49 bool server_error); 50 51 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; 52 const GURL url_; 53 54 // Requests in progress. 55 // TimeZoneProvider owns all requests, so this vector is deleted on destroy. 56 ScopedVector<TimeZoneRequest> requests_; 57 58 // Creation and destruction should happen on the same thread. 59 base::ThreadChecker thread_checker_; 60 61 DISALLOW_COPY_AND_ASSIGN(TimeZoneProvider); 62 }; 63 64 } // namespace chromeos 65 66 #endif // CHROME_BROWSER_CHROMEOS_TIMEZONE_TIMEZONE_PROVIDER_H_ 67