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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 14960004: Fix mismatched parameter expectations between chrome.omnibox setDefaultSuggestion and SuggestResult (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@omniboxJSON
Patch Set: Modify SetOmniboxDefaultSuggestion to generate a dictionary compatible with api::omnibox::SuggestRe… 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/extensions/api/omnibox/omnibox_api.h" 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 kOmniboxDefaultSuggestion, 79 kOmniboxDefaultSuggestion,
80 &dict)) { 80 &dict)) {
81 suggestion.reset(new omnibox::SuggestResult); 81 suggestion.reset(new omnibox::SuggestResult);
82 omnibox::SuggestResult::Populate(*dict, suggestion.get()); 82 omnibox::SuggestResult::Populate(*dict, suggestion.get());
83 } 83 }
84 return suggestion.Pass(); 84 return suggestion.Pass();
85 } 85 }
86 86
87 // Tries to set the omnibox default suggestion; returns true on success or 87 // Tries to set the omnibox default suggestion; returns true on success or
88 // false on failure. 88 // false on failure.
89 bool SetOmniboxDefaultSuggestion(Profile* profile, 89 bool SetOmniboxDefaultSuggestion(
90 const std::string& extension_id, 90 Profile* profile,
91 const omnibox::SuggestResult& suggestion) { 91 const std::string& extension_id,
92 const omnibox::DefaultSuggestResult& suggestion) {
92 ExtensionPrefs* prefs = 93 ExtensionPrefs* prefs =
93 ExtensionSystem::Get(profile)->extension_service()->extension_prefs(); 94 ExtensionSystem::Get(profile)->extension_service()->extension_prefs();
94 if (!prefs) 95 if (!prefs)
95 return false; 96 return false;
96 97
97 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue(); 98 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue();
98 // A default suggestion should not have the content field set. 99 // Add the content field so that the dictionary can be used to populate an
99 dict->Remove(kSuggestionContent, NULL); 100 // omnibox::SuggestResult.
101 dict->SetWithoutPathExpansion(kSuggestionContent, new base::StringValue(""));
100 prefs->UpdateExtensionPref(extension_id, 102 prefs->UpdateExtensionPref(extension_id,
101 kOmniboxDefaultSuggestion, 103 kOmniboxDefaultSuggestion,
102 dict.release()); 104 dict.release());
103 105
104 return true; 106 return true;
105 } 107 }
106 108
107 } // namespace 109 } // namespace
108 110
109 // static 111 // static
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 for (size_t i = 0; i < description_styles.size(); ++i) { 396 for (size_t i = 0; i < description_styles.size(); ++i) {
395 if (description_styles[i].offset > placeholder) 397 if (description_styles[i].offset > placeholder)
396 description_styles[i].offset += replacement.length() - 2; 398 description_styles[i].offset += replacement.length() - 2;
397 } 399 }
398 } 400 }
399 401
400 match->contents.assign(description); 402 match->contents.assign(description);
401 } 403 }
402 404
403 } // namespace extensions 405 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/omnibox/omnibox_unittest.cc » ('j') | chrome/common/extensions/api/omnibox.json » ('J')

Powered by Google App Engine
This is Rietveld 408576698