history.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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
18namespace content {
19class BrowserContext;
20}
21
22namespace app_list {
23
24class HistoryData;
25class HistoryDataStore;
26
27namespace test {
28class SearchHistoryTest;
29}
30
31// History tracks the launch events of the search results and uses HistoryData
32// to build user learning data out of these events. The learning data is stored
33// as associations between user typed query and launched result id. There are
34// primary and secondary associations. See HistoryData comments to see how
35// they are built. The learning data is sent to the mixer to boost results that
36// have been launched before.
37class History : public KeyedService, public HistoryDataObserver {
38 public:
39  explicit History(content::BrowserContext* context);
40  virtual ~History();
41
42  // Returns true if the service is ready.
43  bool IsReady() const;
44
45  // Adds a launch event to the learning data.
46  void AddLaunchEvent(const std::string& query, const std::string& result_id);
47
48  // Gets all known search results that were launched using the given |query|
49  // or using queries that |query| is a prefix of.
50  scoped_ptr<KnownResults> GetKnownResults(const std::string& query) const;
51
52 private:
53  friend class app_list::test::SearchHistoryTest;
54
55  // HistoryDataObserver overrides:
56  virtual void OnHistoryDataLoadedFromStore() OVERRIDE;
57
58  content::BrowserContext* browser_context_;
59  scoped_ptr<HistoryData> data_;
60  scoped_refptr<HistoryDataStore> store_;
61  bool data_loaded_;
62
63  DISALLOW_COPY_AND_ASSIGN(History);
64};
65
66}  // namespace app_list
67
68#endif  // CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_H_
69