Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: chrome/browser/ui/app_list/search/history_data.h

Issue 15875007: app_list: Search result launch history and boost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix guest mode crash Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_DATA_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_H_
7
8 #include <deque>
9 #include <map>
10 #include <string>
11
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/time.h"
17 #include "chrome/browser/ui/app_list/search/history_types.h"
18
19 namespace app_list {
20
21 class HistoryDataObserver;
22 class HistoryDataStore;
23
24 // HistoryData stores the associations of the user typed queries and launched
25 // search result id. There are two types of association: primary and secondary.
26 // Primary is a 1-to-1 mapping between the query and result id. Secondary
27 // is a 1-to-many mapping and only kept the last 5 to limit the data size.
28 // If an association is added for the first time, it is added as a primary
29 // association. Further associations added to the same query are added as
30 // secondary. However, if a secondary association is added twice in a row, it
31 // is promoted to primary and the current primary mapping is demoted into
32 // secondary.
33 class HistoryData : public base::SupportsWeakPtr<HistoryData> {
34 public:
35 typedef std::deque<std::string> SecondaryDeque;
36 // Defines data to be associated with a query.
James Cook 2013/05/23 21:51:08 nit: extra line above might be more readable
xiyuan 2013/05/23 22:38:13 Done.
37 struct Data {
38 Data();
39 ~Data();
40
41 // Primary result associated with the query.
42 std::string primary;
43
44 // Secondary results associated with the query from oldest to latest.
45 SecondaryDeque secondary;
46
47 // Last update time.
48 base::Time update_time;
49 };
50 typedef std::map<std::string, Data> Associations;
51
52 // Constructor of HistoryData. |store| is the storage to persist the data.
53 // |max_entry| is the maximum number of most recent query entries to keep.
54 // |max_secondary| is the maximum number of secondary associations to keep.
55 HistoryData(HistoryDataStore* store, size_t max_entry, size_t max_secondary);
James Cook 2013/05/23 21:51:08 Maybe comment that max_entry is total entries, inc
xiyuan 2013/05/23 22:38:13 Renamed max_entry to max_primary.
56 ~HistoryData();
57
58 // Adds an association.
59 void Add(const std::string& query, const std::string& result_id);
60
61 // Gets all known search results that were launched using the given |query|
62 // or the queries that |query| is a prefix of.
63 scoped_ptr<KnownResults> GetKnownResults(const std::string& query) const;
64
65 void AddObserver(HistoryDataObserver* observer);
66 void RemoveObserver(HistoryDataObserver* observer);
67
68 const Associations& associations() const { return associations_; }
69
70 private:
71 // Invoked from |store| with loaded data.
72 void OnStoreLoaded(scoped_ptr<Associations> loaded_data);
73
74 // Trims the data to keep the most recent |max_entry_| queries.
75 void TrimEntries();
76
77 HistoryDataStore* store_; // Not owned.
78 const size_t max_entry_;
79 const size_t max_secondary_;
80 ObserverList<HistoryDataObserver, true> observers_;
81
82 Associations associations_;
83
84 DISALLOW_COPY_AND_ASSIGN(HistoryData);
85 };
86
87 } // namespace app_list
88
89 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698