| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef COMPONENTS_ARC_INTENT_HELPER_LINK_HANDLER_MODEL_IMPL_H_ | 5 #ifndef COMPONENTS_ARC_INTENT_HELPER_LINK_HANDLER_MODEL_IMPL_H_ |
| 6 #define COMPONENTS_ARC_INTENT_HELPER_LINK_HANDLER_MODEL_IMPL_H_ | 6 #define COMPONENTS_ARC_INTENT_HELPER_LINK_HANDLER_MODEL_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/link_handler_model.h" | 11 #include "ash/link_handler_model.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 15 #include "components/arc/arc_service.h" | |
| 16 #include "components/arc/common/intent_helper.mojom.h" | 14 #include "components/arc/common/intent_helper.mojom.h" |
| 17 #include "components/arc/intent_helper/activity_icon_loader.h" | 15 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 16 #include "url/gurl.h" |
| 18 | 17 |
| 19 namespace arc { | 18 namespace arc { |
| 20 | 19 |
| 21 class LinkHandlerModelImpl : public ash::LinkHandlerModel { | 20 class LinkHandlerModelImpl : public ash::LinkHandlerModel { |
| 22 public: | 21 public: |
| 23 explicit LinkHandlerModelImpl(scoped_refptr<ActivityIconLoader> icon_loader); | 22 LinkHandlerModelImpl(); |
| 24 ~LinkHandlerModelImpl() override; | 23 ~LinkHandlerModelImpl() override; |
| 25 | 24 |
| 26 // ash::LinkHandlerModel overrides: | 25 // ash::LinkHandlerModel overrides: |
| 27 void AddObserver(Observer* observer) override; | 26 void AddObserver(Observer* observer) override; |
| 28 void OpenLinkWithHandler(const GURL& url, uint32_t handler_id) override; | 27 void OpenLinkWithHandler(const GURL& url, uint32_t handler_id) override; |
| 29 | 28 |
| 30 // Starts retrieving handler information for the |url| and returns true. | 29 // Starts retrieving handler information for the |url| and returns true. |
| 31 // Returns false when the information cannot be retrieved. In that case, | 30 // Returns false when the information cannot be retrieved. In that case, |
| 32 // the caller should delete |this| object. | 31 // the caller should delete |this| object. |
| 33 bool Init(const GURL& url); | 32 bool Init(const GURL& url); |
| 34 | 33 |
| 35 static GURL RewriteUrlFromQueryIfAvailableForTesting(const GURL& url); | 34 static GURL RewriteUrlFromQueryIfAvailableForTesting(const GURL& url); |
| 36 | 35 |
| 37 private: | 36 private: |
| 38 mojom::IntentHelperInstance* GetIntentHelper(); | 37 mojom::IntentHelperInstance* GetIntentHelper(); |
| 39 void OnUrlHandlerList(std::vector<mojom::IntentHandlerInfoPtr> handlers); | 38 void OnUrlHandlerList(std::vector<mojom::IntentHandlerInfoPtr> handlers); |
| 40 void NotifyObserver( | 39 void NotifyObserver( |
| 41 std::unique_ptr<ActivityIconLoader::ActivityToIconsMap> icons); | 40 std::unique_ptr<ArcIntentHelperBridge::ActivityToIconsMap> icons); |
| 42 | 41 |
| 43 // Checks if the |url| matches the following pattern: | 42 // Checks if the |url| matches the following pattern: |
| 44 // "http(s)://<valid_google_hostname>/url?...&url=<valid_url>&..." | 43 // "http(s)://<valid_google_hostname>/url?...&url=<valid_url>&..." |
| 45 // If it does, creates a new GURL object from the <valid_url> and returns it. | 44 // If it does, creates a new GURL object from the <valid_url> and returns it. |
| 46 // Otherwise, returns the original |url| as-us. | 45 // Otherwise, returns the original |url| as-us. |
| 47 static GURL RewriteUrlFromQueryIfAvailable(const GURL& url); | 46 static GURL RewriteUrlFromQueryIfAvailable(const GURL& url); |
| 48 | 47 |
| 49 base::ObserverList<Observer> observer_list_; | 48 base::ObserverList<Observer> observer_list_; |
| 50 | 49 |
| 51 // Url handler info passed from ARC. | 50 // Url handler info passed from ARC. |
| 52 std::vector<mojom::IntentHandlerInfoPtr> handlers_; | 51 std::vector<mojom::IntentHandlerInfoPtr> handlers_; |
| 53 // Activity icon info passed from ARC. | 52 // Activity icon info passed from ARC. |
| 54 ActivityIconLoader::ActivityToIconsMap icons_; | 53 ArcIntentHelperBridge::ActivityToIconsMap icons_; |
| 55 | |
| 56 // Use refptr to retain the object even if ArcIntentHelperBridge is destructed | |
| 57 // first. | |
| 58 scoped_refptr<ActivityIconLoader> icon_loader_; | |
| 59 | 54 |
| 60 // Always keep this the last member of this class to make sure it's the | 55 // Always keep this the last member of this class to make sure it's the |
| 61 // first thing to be destructed. | 56 // first thing to be destructed. |
| 62 base::WeakPtrFactory<LinkHandlerModelImpl> weak_ptr_factory_; | 57 base::WeakPtrFactory<LinkHandlerModelImpl> weak_ptr_factory_; |
| 63 | 58 |
| 64 DISALLOW_COPY_AND_ASSIGN(LinkHandlerModelImpl); | 59 DISALLOW_COPY_AND_ASSIGN(LinkHandlerModelImpl); |
| 65 }; | 60 }; |
| 66 | 61 |
| 67 } // namespace arc | 62 } // namespace arc |
| 68 | 63 |
| 69 #endif // COMPONENTS_ARC_INTENT_HELPER_LINK_HANDLER_MODEL_IMPL_H_ | 64 #endif // COMPONENTS_ARC_INTENT_HELPER_LINK_HANDLER_MODEL_IMPL_H_ |
| OLD | NEW |