Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / android / android_history_types.cc
1 // Copyright (c) 2012 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 #include "chrome/browser/history/android/android_history_types.h"
6
7 namespace history {
8
9 namespace {
10 // The column name defined in android.provider.Browser.BookmarkColumns
11 const char* const kAndroidBookmarkColumn[] = {
12     "_id",
13     "url",
14     "title",
15     "created",
16     "date",
17     "visits",
18     "favicon",
19     "bookmark",
20     "raw_url",
21 };
22
23 // The column name defined in android.provider.Browser.SearchColumns
24 const char* const kAndroidSearchColumn[] = {
25     "_id",
26     "search",
27     "date",
28 };
29
30 class BookmarkIDMapping : public std::map<std::string,
31                                           HistoryAndBookmarkRow::ColumnID> {
32  public:
33   BookmarkIDMapping() {
34     COMPILE_ASSERT(arraysize(kAndroidBookmarkColumn) <=
35                    HistoryAndBookmarkRow::COLUMN_END,
36                    Array_size_must_not_exceed_enum);
37     for (size_t i = 0; i < arraysize(kAndroidBookmarkColumn); ++i) {
38       (*this)[kAndroidBookmarkColumn[i]] =
39           static_cast<HistoryAndBookmarkRow::ColumnID>(i);
40     }
41   }
42 };
43
44 // The mapping from Android column name to ColumnID; It is initialized
45 // once it used.
46 BookmarkIDMapping* g_bookmark_id_mapping = NULL;
47
48 class SearchIDMapping : public std::map<std::string,
49                                         SearchRow::ColumnID> {
50  public:
51   SearchIDMapping() {
52     COMPILE_ASSERT(arraysize(kAndroidSearchColumn) <= SearchRow::COLUMN_END,
53                    Array_size_must_not_exceed_enum);
54     for (size_t i = 0; i < arraysize(kAndroidSearchColumn); ++i) {
55       (*this)[kAndroidSearchColumn[i]] =
56               static_cast<SearchRow::ColumnID>(i);
57     }
58   }
59 };
60
61 // The mapping from Android column name to ColumnID; It is initialized
62 // once it used.
63 SearchIDMapping* g_search_id_mapping = NULL;
64
65 }  // namespace
66
67 HistoryAndBookmarkRow::HistoryAndBookmarkRow()
68     : id_(0),
69       created_(base::Time()),
70       last_visit_time_(base::Time()),
71       visit_count_(0),
72       is_bookmark_(false),
73       parent_id_(0),
74       url_id_(0) {
75 }
76
77 HistoryAndBookmarkRow::~HistoryAndBookmarkRow() {
78 }
79
80 std::string HistoryAndBookmarkRow::GetAndroidName(ColumnID id) {
81   return kAndroidBookmarkColumn[id];
82 }
83
84 HistoryAndBookmarkRow::ColumnID HistoryAndBookmarkRow::GetColumnID(
85     const std::string& name) {
86   if (!g_bookmark_id_mapping)
87     g_bookmark_id_mapping = new BookmarkIDMapping();
88
89   BookmarkIDMapping::const_iterator i = g_bookmark_id_mapping->find(name);
90   if (i == g_bookmark_id_mapping->end())
91     return HistoryAndBookmarkRow::COLUMN_END;
92   else
93     return i->second;
94 }
95
96 SearchRow::SearchRow()
97     : id_(0),
98       keyword_id_(0) {
99 }
100
101 SearchRow::~SearchRow() {
102 }
103
104 std::string SearchRow::GetAndroidName(ColumnID id) {
105   return kAndroidSearchColumn[id];
106 }
107
108 SearchRow::ColumnID SearchRow::GetColumnID(
109     const std::string& name) {
110   if (!g_search_id_mapping)
111     g_search_id_mapping = new SearchIDMapping();
112
113   SearchIDMapping::const_iterator i = g_search_id_mapping->find(name);
114   if (i == g_search_id_mapping->end())
115     return SearchRow:: COLUMN_END;
116   else
117     return i->second;
118 }
119
120 AndroidURLRow::AndroidURLRow()
121     : id(0),
122       url_id(0) {
123 }
124
125 AndroidURLRow::~AndroidURLRow() {
126 }
127
128 SearchTermRow::SearchTermRow()
129     : id(0) {
130 }
131
132 SearchTermRow::~SearchTermRow() {
133 }
134
135 AndroidStatement::AndroidStatement(sql::Statement* statement, int favicon_index)
136     : statement_(statement),
137       favicon_index_(favicon_index) {
138 }
139
140 AndroidStatement::~AndroidStatement() {
141 }
142
143 }  // namespace history.