Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / search / suggestions / suggestions_service.h
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_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
7
8 #include <vector>
9
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"
17 #include "url/gurl.h"
18
19 class Profile;
20
21 namespace suggestions {
22
23 extern const char kSuggestionsFieldTrialName[];
24 extern const char kSuggestionsFieldTrialURLParam[];
25 extern const char kSuggestionsFieldTrialStateParam[];
26 extern const char kSuggestionsFieldTrialStateEnabled[];
27
28 // Provides an interface for the Suggestions component that provides server
29 // suggestions.
30 class SuggestionsService : public BrowserContextKeyedService,
31                            public net::URLFetcherDelegate {
32  public:
33   explicit SuggestionsService(Profile* profile);
34   virtual ~SuggestionsService();
35
36   // Whether this service is enabled.
37   static bool IsEnabled();
38
39   const SuggestionsProfile& suggestions() { return suggestions_; }
40
41  private:
42   FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData);
43
44   // Starts the fetching process once, where |OnURLFetchComplete| is called with
45   // the response.
46   void FetchSuggestionsData();
47
48   // net::URLFetcherDelegate implementation:
49   virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
50
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_;
54
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_;
58
59   // The URL to fetch suggestions data from.
60   GURL suggestions_url_;
61
62   // Stores the suggestions as they were received from the server.
63   SuggestionsProfile suggestions_;
64
65   Profile* profile_;
66
67   DISALLOW_COPY_AND_ASSIGN(SuggestionsService);
68 };
69
70 }  // namespace suggestions
71
72 #endif  // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_