| OLD | NEW |
| 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/background/background_contents_service.h" | 5 #include "chrome/browser/background/background_contents_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "base/values.h" | 21 #include "base/values.h" |
| 21 #include "chrome/browser/apps/app_load_service.h" | 22 #include "chrome/browser/apps/app_load_service.h" |
| 22 #include "chrome/browser/background/background_contents_service_factory.h" | 23 #include "chrome/browser/background/background_contents_service_factory.h" |
| 23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 DictionaryPrefUpdate update(prefs_, prefs::kRegisteredBackgroundContents); | 757 DictionaryPrefUpdate update(prefs_, prefs::kRegisteredBackgroundContents); |
| 757 base::DictionaryValue* pref = update.Get(); | 758 base::DictionaryValue* pref = update.Get(); |
| 758 const base::string16& appid = GetParentApplicationId(background_contents); | 759 const base::string16& appid = GetParentApplicationId(background_contents); |
| 759 base::DictionaryValue* current; | 760 base::DictionaryValue* current; |
| 760 if (pref->GetDictionaryWithoutPathExpansion(base::UTF16ToUTF8(appid), | 761 if (pref->GetDictionaryWithoutPathExpansion(base::UTF16ToUTF8(appid), |
| 761 ¤t)) { | 762 ¤t)) { |
| 762 return; | 763 return; |
| 763 } | 764 } |
| 764 | 765 |
| 765 // No entry for this application yet, so add one. | 766 // No entry for this application yet, so add one. |
| 766 base::DictionaryValue* dict = new base::DictionaryValue(); | 767 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 767 dict->SetString(kUrlKey, background_contents->GetURL().spec()); | 768 dict->SetString(kUrlKey, background_contents->GetURL().spec()); |
| 768 dict->SetString(kFrameNameKey, contents_map_[appid].frame_name); | 769 dict->SetString(kFrameNameKey, contents_map_[appid].frame_name); |
| 769 pref->SetWithoutPathExpansion(base::UTF16ToUTF8(appid), dict); | 770 pref->SetWithoutPathExpansion(base::UTF16ToUTF8(appid), std::move(dict)); |
| 770 } | 771 } |
| 771 | 772 |
| 772 bool BackgroundContentsService::HasRegisteredBackgroundContents( | 773 bool BackgroundContentsService::HasRegisteredBackgroundContents( |
| 773 const base::string16& app_id) { | 774 const base::string16& app_id) { |
| 774 if (!prefs_) | 775 if (!prefs_) |
| 775 return false; | 776 return false; |
| 776 std::string app = base::UTF16ToUTF8(app_id); | 777 std::string app = base::UTF16ToUTF8(app_id); |
| 777 const base::DictionaryValue* contents = | 778 const base::DictionaryValue* contents = |
| 778 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); | 779 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); |
| 779 return contents->HasKey(app); | 780 return contents->HasKey(app); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 const gfx::Rect& initial_rect, | 849 const gfx::Rect& initial_rect, |
| 849 bool user_gesture, | 850 bool user_gesture, |
| 850 bool* was_blocked) { | 851 bool* was_blocked) { |
| 851 Browser* browser = chrome::FindLastActiveWithProfile( | 852 Browser* browser = chrome::FindLastActiveWithProfile( |
| 852 Profile::FromBrowserContext(new_contents->GetBrowserContext())); | 853 Profile::FromBrowserContext(new_contents->GetBrowserContext())); |
| 853 if (browser) { | 854 if (browser) { |
| 854 chrome::AddWebContents(browser, NULL, new_contents, disposition, | 855 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
| 855 initial_rect, user_gesture, was_blocked); | 856 initial_rect, user_gesture, was_blocked); |
| 856 } | 857 } |
| 857 } | 858 } |
| OLD | NEW |