Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / search / history.h
1 // Copyright 2013 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_APP_LIST_SEARCH_HISTORY_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/ui/app_list/search/history_data_observer.h"
15 #include "chrome/browser/ui/app_list/search/history_types.h"
16 #include "components/keyed_service/core/keyed_service.h"
17
18 namespace app_list {
19
20 class HistoryData;
21 class HistoryDataStore;
22
23 namespace test {
24 class SearchHistoryTest;
25 }
26
27 // History tracks the launch events of the search results and uses HistoryData
28 // to build user learning data out of these events. The learning data is stored
29 // as associations between user typed query and launched result id. There are
30 // primary and secondary associations. See HistoryData comments to see how
31 // they are built. The learning data is sent to the mixer to boost results that
32 // have been launched before.
33 class History : public KeyedService, public HistoryDataObserver {
34  public:
35   explicit History(scoped_refptr<HistoryDataStore> store);
36   virtual ~History();
37
38   // Returns true if the service is ready.
39   bool IsReady() const;
40
41   // Adds a launch event to the learning data.
42   void AddLaunchEvent(const std::string& query, const std::string& result_id);
43
44   // Gets all known search results that were launched using the given |query|
45   // or using queries that |query| is a prefix of.
46   scoped_ptr<KnownResults> GetKnownResults(const std::string& query) const;
47
48  private:
49   friend class app_list::test::SearchHistoryTest;
50
51   // HistoryDataObserver overrides:
52   virtual void OnHistoryDataLoadedFromStore() OVERRIDE;
53
54   scoped_ptr<HistoryData> data_;
55   scoped_refptr<HistoryDataStore> store_;
56   bool data_loaded_;
57
58   DISALLOW_COPY_AND_ASSIGN(History);
59 };
60
61 }  // namespace app_list
62
63 #endif  // CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_H_