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.
5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h"
15 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
16 #include "net/url_request/url_fetcher_delegate.h"
21 namespace suggestions {
23 extern const char kSuggestionsFieldTrialName[];
24 extern const char kSuggestionsFieldTrialURLParam[];
25 extern const char kSuggestionsFieldTrialStateParam[];
26 extern const char kSuggestionsFieldTrialStateEnabled[];
28 // Provides an interface for the Suggestions component that provides server
30 class SuggestionsService : public BrowserContextKeyedService,
31 public net::URLFetcherDelegate {
33 explicit SuggestionsService(Profile* profile);
34 virtual ~SuggestionsService();
36 // Whether this service is enabled.
37 static bool IsEnabled();
39 const SuggestionsProfile& suggestions() { return suggestions_; }
42 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData);
44 // Starts the fetching process once, where |OnURLFetchComplete| is called with
46 void FetchSuggestionsData();
48 // net::URLFetcherDelegate implementation:
49 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
51 // Contains the current suggestions request. Will only have a value while a
52 // request is pending, and will be reset by |OnURLFetchComplete|.
53 scoped_ptr<net::URLFetcher> pending_request_;
55 // The start time of the last suggestions request. This is used to measure the
56 // latency of requests. Initially zero.
57 base::TimeTicks last_request_started_time_;
59 // The URL to fetch suggestions data from.
60 GURL suggestions_url_;
62 // Stores the suggestions as they were received from the server.
63 SuggestionsProfile suggestions_;
67 DISALLOW_COPY_AND_ASSIGN(SuggestionsService);
70 } // namespace suggestions
72 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_