summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/shortcuts_provider_shortcut.h
blob: 6e4297780f817405891448957a583fb1322ae4d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_SHORTCUT_H_
#define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_SHORTCUT_H_
#pragma once

#include <map>
#include <string>
#include <vector>

#include "base/string16.h"
#include "base/time.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "googleurl/src/gurl.h"

namespace shortcuts_provider {

// The following struct encapsulates one previously selected omnibox shortcut.
struct Shortcut {
  Shortcut(const string16& text,
           const GURL& url,
           const string16& contents,
           const ACMatchClassifications& contents_class,
           const string16& description,
           const ACMatchClassifications& description_class);
  // This constructor is used for creation of the structure from DB data.
  Shortcut(const std::string& id,
           const string16& text,
           const string16& url,
           const string16& contents,
           const string16& contents_class,
           const string16& description,
           const string16& description_class,
           int64 time_of_last_access,
           int   number_of_hits);
  // Required for STL, we don't use this directly.
  Shortcut();
  ~Shortcut();

  string16 contents_class_as_str() const;
  string16 description_class_as_str() const;

  std::string id;  // Unique guid for the shortcut.
  string16 text;  // The user's original input string.
  GURL url;       // The corresponding destination URL.

  // Contents and description from the original match, along with their
  // corresponding markup. We need these in order to correctly mark which
  // parts are URLs, dim, etc. However, we strip all MATCH classifications
  // from these since we'll mark the matching portions ourselves as we match
  // the user's current typing against these Shortcuts.
  string16 contents;
  ACMatchClassifications contents_class;
  string16 description;
  ACMatchClassifications description_class;

  base::Time last_access_time;  // Last time shortcut was selected.
  int number_of_hits;           // How many times shortcut was selected.
};

// Maps the original match (|text| in the Shortcut) to Shortcut for quick
// search.
typedef std::multimap<string16, Shortcut> ShortcutMap;

// Quick access guid maps - first one for loading, the second one is a shadow
// map for access.
typedef std::map<std::string, Shortcut> GuidToShortcutMap;
typedef std::map<std::string, ShortcutMap::iterator> GuidToShortcutsIteratorMap;

// Helpers dealing with database update.
// Converts spans vector to comma-separated string.
string16 SpansToString(const ACMatchClassifications& value);
// Coverts comma-separated unsigned integer values into spans vector.
ACMatchClassifications SpansFromString(const string16& value);

// Helper for initialization and update.
// Adds match at the end if and only if its style is different from the last
// match.
void AddLastMatchIfNeeded(ACMatchClassifications* matches,
                          int position,
                          int style);
}  // namespace shortcuts_provider

#endif  // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_SHORTCUT_H_