| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/webdata/web_intents_table.h" | 5 #include "chrome/browser/webdata/web_intents_table.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "sql/statement.h" | 9 #include "sql/statement.h" |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 intent.service_url = GURL(tmp); | 62 intent.service_url = GURL(tmp); |
| 63 | 63 |
| 64 intent.action = s.ColumnString16(1); | 64 intent.action = s.ColumnString16(1); |
| 65 intent.type = s.ColumnString16(2); | 65 intent.type = s.ColumnString16(2); |
| 66 | 66 |
| 67 intents->push_back(intent); | 67 intents->push_back(intent); |
| 68 } | 68 } |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool WebIntentsTable::GetAllWebIntents(std::vector<WebIntentData>* intents) { |
| 73 DCHECK(intents); |
| 74 sql::Statement s(db_->GetUniqueStatement( |
| 75 "SELECT service_url, action, type FROM web_intents ")); |
| 76 if (!s) { |
| 77 NOTREACHED() << "Statement prepare failed"; |
| 78 return false; |
| 79 } |
| 80 |
| 81 while (s.Step()) { |
| 82 WebIntentData intent; |
| 83 string16 tmp = s.ColumnString16(0); |
| 84 intent.service_url = GURL(tmp); |
| 85 |
| 86 intent.action = s.ColumnString16(1); |
| 87 intent.type = s.ColumnString16(2); |
| 88 |
| 89 intents->push_back(intent); |
| 90 } |
| 91 return true; |
| 92 } |
| 93 |
| 72 bool WebIntentsTable::SetWebIntent(const WebIntentData& intent) { | 94 bool WebIntentsTable::SetWebIntent(const WebIntentData& intent) { |
| 73 sql::Statement s(db_->GetUniqueStatement( | 95 sql::Statement s(db_->GetUniqueStatement( |
| 74 "INSERT OR REPLACE INTO web_intents (service_url, type, action, title) " | 96 "INSERT OR REPLACE INTO web_intents (service_url, type, action, title) " |
| 75 "VALUES (?, ?, ?, ?)")); | 97 "VALUES (?, ?, ?, ?)")); |
| 76 if (!s) { | 98 if (!s) { |
| 77 NOTREACHED() << "Statement prepare failed"; | 99 NOTREACHED() << "Statement prepare failed"; |
| 78 return false; | 100 return false; |
| 79 } | 101 } |
| 80 | 102 |
| 81 s.BindString(0, intent.service_url.spec()); | 103 s.BindString(0, intent.service_url.spec()); |
| 82 s.BindString16(1, intent.type); | 104 s.BindString16(1, intent.type); |
| 83 s.BindString16(2, intent.action); | 105 s.BindString16(2, intent.action); |
| 84 s.BindString16(3, intent.title); | 106 s.BindString16(3, intent.title); |
| 85 return s.Run(); | 107 return s.Run(); |
| 86 } | 108 } |
| 87 | |
| 88 // TODO(jhawkins): Investigate the need to remove rows matching only | 109 // TODO(jhawkins): Investigate the need to remove rows matching only |
| 89 // |intent.service_url|. It's unlikely the user will be given the ability to | 110 // |intent.service_url|. It's unlikely the user will be given the ability to |
| 90 // remove at the granularity of actions or types. | 111 // remove at the granularity of actions or types. |
| 91 bool WebIntentsTable::RemoveWebIntent(const WebIntentData& intent) { | 112 bool WebIntentsTable::RemoveWebIntent(const WebIntentData& intent) { |
| 92 sql::Statement delete_s(db_->GetUniqueStatement( | 113 sql::Statement s(db_->GetUniqueStatement( |
| 93 "DELETE FROM web_intents " | 114 "DELETE FROM web_intents " |
| 94 "WHERE service_url = ? AND action = ? AND type = ?")); | 115 "WHERE service_url = ? AND action = ? AND type = ?")); |
| 95 if (!delete_s) { | 116 if (!s) { |
| 96 NOTREACHED() << "Statement prepare failed"; | 117 NOTREACHED() << "Statement prepare failed"; |
| 97 return false; | 118 return false; |
| 98 } | 119 } |
| 99 | 120 |
| 100 delete_s.BindString(0, intent.service_url.spec()); | 121 s.BindString(0, intent.service_url.spec()); |
| 101 delete_s.BindString16(1, intent.action); | 122 s.BindString16(1, intent.action); |
| 102 delete_s.BindString16(2, intent.type); | 123 s.BindString16(2, intent.type); |
| 103 return delete_s.Run(); | 124 return s.Run(); |
| 104 } | 125 } |
| 105 | 126 |
| OLD | NEW |