Skip to content

Commit

Permalink
[iOS] Move ios/c/b/app_launcher to model subfolder
Browse files Browse the repository at this point in the history
To simplify the folder hierarchy on iOS and have a clearer layer
separation, all the files in ios/c/b/<foo>/ will be moved to
ios/c/b/<foo>/model/ to showcase that they are model files.

Bug: 1319852
Change-Id: I46652a8a29a858dbd00e78980d74b6dbc7a1da76
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4797788
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: Quentin Pubert <qpubert@google.com>
Cr-Commit-Position: refs/heads/main@{#1187174}
  • Loading branch information
Gauthier Ambard authored and Chromium LUCI CQ committed Aug 23, 2023
1 parent 3d7677e commit 02a3527
Show file tree
Hide file tree
Showing 29 changed files with 79 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import("//build/config/ios/rules.gni")

source_set("app_launcher") {
source_set("model") {
sources = [
"app_launcher_abuse_detector.h",
"app_launcher_abuse_detector.mm",
Expand Down Expand Up @@ -45,7 +45,7 @@ source_set("test_support") {
"fake_app_launcher_abuse_detector.mm",
]
deps = [
":app_launcher",
":model",
"//base",
]
}
Expand All @@ -59,7 +59,7 @@ source_set("unit_tests") {
"app_launching_state_unittest.mm",
]
deps = [
":app_launcher",
":model",
":test_support",
"//base",
"//base/test:test_support",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_ABUSE_DETECTOR_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_ABUSE_DETECTOR_H_
#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_ABUSE_DETECTOR_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_ABUSE_DETECTOR_H_

#import <Foundation/Foundation.h>

Expand Down Expand Up @@ -48,4 +48,4 @@ extern const int kMaxAllowedConsecutiveExternalAppLaunches;
fromSourcePageURL:(const GURL&)sourcePageURL;
@end

#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_ABUSE_DETECTOR_H_
#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_ABUSE_DETECTOR_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/app_launcher_abuse_detector.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_abuse_detector.h"

#import "base/metrics/histogram_macros.h"
#import "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/app_launcher/app_launching_state.h"
#import "ios/chrome/browser/app_launcher/model/app_launching_state.h"
#import "url/gurl.h"

const int kMaxAllowedConsecutiveExternalAppLaunches = 2;
Expand Down Expand Up @@ -58,8 +58,9 @@ - (instancetype)init {
- (void)didRequestLaunchExternalAppURL:(const GURL&)URL
fromSourcePageURL:(const GURL&)sourcePageURL {
NSString* key = [[self class] stateKeyForAppURL:URL sourceURL:sourcePageURL];
if (!_appLaunchingStates[key])
if (!_appLaunchingStates[key]) {
_appLaunchingStates[key] = [[AppLaunchingState alloc] init];
}
[_appLaunchingStates[key] updateWithLaunchRequest];
}

Expand All @@ -69,17 +70,20 @@ - (ExternalAppLaunchPolicy)launchPolicyForURL:(const GURL&)URL
bool isChromeLaunchAttempt = HasChromeAppLaunchScheme(URL);
UMA_HISTOGRAM_BOOLEAN("IOS.AppLauncher.AppURLHasChromeLaunchScheme",
isChromeLaunchAttempt);
if (isChromeLaunchAttempt)
if (isChromeLaunchAttempt) {
return ExternalAppLaunchPolicyBlock;
}

NSString* key = [[self class] stateKeyForAppURL:URL sourceURL:sourcePageURL];
// Don't block apps that are not registered with the abuse detector.
if (!_appLaunchingStates[key])
if (!_appLaunchingStates[key]) {
return ExternalAppLaunchPolicyAllow;
}

AppLaunchingState* state = _appLaunchingStates[key];
if ([state isAppLaunchingBlocked])
if ([state isAppLaunchingBlocked]) {
return ExternalAppLaunchPolicyBlock;
}

if (state.consecutiveLaunchesCount >
kMaxAllowedConsecutiveExternalAppLaunches) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/app_launcher_abuse_detector.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_abuse_detector.h"

#import "testing/gtest/include/gtest/gtest.h"
#import "testing/platform_test.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_BROWSER_AGENT_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_BROWSER_AGENT_H_
#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_BROWSER_AGENT_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_BROWSER_AGENT_H_

#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h"
#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper_delegate.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_tab_helper.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_tab_helper_delegate.h"
#import "ios/chrome/browser/shared/model/browser/browser_user_data.h"
#import "ios/chrome/browser/tabs/tab_helper_delegate_installer.h"

Expand Down Expand Up @@ -58,4 +58,4 @@ class AppLauncherBrowserAgent
BROWSER_USER_DATA_KEY_DECL();
};

#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_BROWSER_AGENT_H_
#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_BROWSER_AGENT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/app_launcher_browser_agent.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_browser_agent.h"

#import "base/check.h"
#import "base/functional/bind.h"
#import "base/metrics/histogram_macros.h"
#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_tab_helper.h"
#import "ios/chrome/browser/mailto_handler/mailto_handler_service.h"
#import "ios/chrome/browser/mailto_handler/mailto_handler_service_factory.h"
#import "ios/chrome/browser/overlays/public/overlay_callback_manager.h"
Expand All @@ -26,8 +26,8 @@

BROWSER_USER_DATA_KEY_IMPL(AppLauncherBrowserAgent)

using app_launcher_overlays::AppLaunchConfirmationRequest;
using app_launcher_overlays::AllowAppLaunchResponse;
using app_launcher_overlays::AppLaunchConfirmationRequest;

namespace {
// Records histogram metric on the user's response when prompted to open another
Expand All @@ -46,8 +46,9 @@ void AppLauncherOverlayCallback(base::OnceCallback<void(bool)> completion,
bool user_accepted = response && response->GetInfo<AllowAppLaunchResponse>();

// Record the UMA for repeated requests.
if (repeated_request)
if (repeated_request) {
RecordUserAcceptedAppLaunchMetric(user_accepted);
}

// Execute the completion with the response.
DCHECK(!completion.is_null());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/app_launcher_browser_agent.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_browser_agent.h"

#import <UIKit/UIKit.h>
#import <map>

#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h"
#import "ios/chrome/browser/app_launcher/fake_app_launcher_abuse_detector.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_tab_helper.h"
#import "ios/chrome/browser/app_launcher/model/fake_app_launcher_abuse_detector.h"
#import "ios/chrome/browser/overlays/public/overlay_callback_manager.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_request_queue.h"
Expand All @@ -27,8 +27,8 @@
#import "third_party/ocmock/OCMock/OCMock.h"
#import "url/gurl.h"

using app_launcher_overlays::AppLaunchConfirmationRequest;
using app_launcher_overlays::AllowAppLaunchResponse;
using app_launcher_overlays::AppLaunchConfirmationRequest;

// Test fixture for AppLauncherBrowserAgent.
class AppLauncherBrowserAgentTest : public PlatformTest {
Expand Down Expand Up @@ -86,8 +86,9 @@ bool IsShowingDialog(web::WebState* web_state, bool is_repeated_request) {
OverlayRequest* request = OverlayRequestQueue::FromWebState(
web_state, OverlayModality::kWebContentArea)
->front_request();
if (!request)
if (!request) {
return false;
}

AppLaunchConfirmationRequest* config =
request->GetConfig<AppLaunchConfirmationRequest>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_TAB_HELPER_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_TAB_HELPER_H_
#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_TAB_HELPER_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_TAB_HELPER_H_

#import "ios/web/public/navigation/web_state_policy_decider.h"
#import "ios/web/public/web_state_user_data.h"
Expand Down Expand Up @@ -115,4 +115,4 @@ class AppLauncherTabHelper
WEB_STATE_USER_DATA_KEY_DECL();
};

#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_TAB_HELPER_H_
#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_TAB_HELPER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_tab_helper.h"

#import <UIKit/UIKit.h>

Expand All @@ -11,8 +11,8 @@
#import "base/strings/sys_string_conversions.h"
#import "components/policy/core/browser/url_blocklist_manager.h"
#import "components/reading_list/core/reading_list_model.h"
#import "ios/chrome/browser/app_launcher/app_launcher_abuse_detector.h"
#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper_delegate.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_abuse_detector.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_tab_helper_delegate.h"
#import "ios/chrome/browser/policy_url_blocking/policy_url_blocking_service.h"
#import "ios/chrome/browser/policy_url_blocking/policy_url_blocking_util.h"
#import "ios/chrome/browser/reading_list/reading_list_model_factory.h"
Expand All @@ -28,16 +28,19 @@
namespace {

bool IsValidAppUrl(const GURL& app_url) {
if (!app_url.is_valid())
if (!app_url.is_valid()) {
return false;
}

if (!app_url.has_scheme())
if (!app_url.has_scheme()) {
return false;
}

// Block attempts to open this application's settings in the native system
// settings application.
if (app_url.SchemeIs("app-settings"))
if (app_url.SchemeIs("app-settings")) {
return false;
}
return true;
}

Expand Down Expand Up @@ -123,8 +126,9 @@ bool HasChromeAppScheme(const GURL& app_url) {
is_prompt_active_ = true;
base::WeakPtr<AppLauncherTabHelper> weak_this =
weak_factory_.GetWeakPtr();
if (!delegate_)
if (!delegate_) {
return;
}
delegate_->ShowRepeatedAppLaunchAlert(
this,
base::BindOnce(&AppLauncherTabHelper::ShowRepeatedAppLaunchAlertDone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_TAB_HELPER_DELEGATE_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_TAB_HELPER_DELEGATE_H_
#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_TAB_HELPER_DELEGATE_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_TAB_HELPER_DELEGATE_H_

#include "base/functional/callback.h"

Expand Down Expand Up @@ -31,4 +31,4 @@ class AppLauncherTabHelperDelegate {
base::OnceCallback<void(bool)> completion) = 0;
};

#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHER_TAB_HELPER_DELEGATE_H_
#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHER_TAB_HELPER_DELEGATE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_tab_helper.h"

#import <memory>

Expand All @@ -16,8 +16,8 @@
#import "components/policy/policy_constants.h"
#import "components/reading_list/core/reading_list_entry.h"
#import "components/reading_list/core/reading_list_model.h"
#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper_delegate.h"
#import "ios/chrome/browser/app_launcher/fake_app_launcher_abuse_detector.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_tab_helper_delegate.h"
#import "ios/chrome/browser/app_launcher/model/fake_app_launcher_abuse_detector.h"
#import "ios/chrome/browser/policy/enterprise_policy_test_helper.h"
#import "ios/chrome/browser/policy_url_blocking/policy_url_blocking_service.h"
#import "ios/chrome/browser/reading_list/reading_list_model_factory.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHING_STATE_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHING_STATE_H_
#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHING_STATE_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHING_STATE_H_

#import <Foundation/Foundation.h>

Expand Down Expand Up @@ -33,4 +33,4 @@ extern const double kDefaultMaxSecondsBetweenConsecutiveExternalAppLaunches;
- (void)updateWithLaunchRequest;
@end

#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_APP_LAUNCHING_STATE_H_
#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_APP_LAUNCHING_STATE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/app_launching_state.h"
#import "ios/chrome/browser/app_launcher/model/app_launching_state.h"

const double kDefaultMaxSecondsBetweenConsecutiveExternalAppLaunches = 30.0;

Expand All @@ -24,8 +24,9 @@ + (void)setMaxSecondsBetweenConsecutiveLaunches:(double)seconds {
}

- (void)updateWithLaunchRequest {
if (_appLaunchingBlocked)
if (_appLaunchingBlocked) {
return;
}
if (!_lastAppLaunchTime ||
-_lastAppLaunchTime.timeIntervalSinceNow >
[[self class] maxSecondsBetweenConsecutiveLaunches]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/app_launching_state.h"
#import "ios/chrome/browser/app_launcher/model/app_launching_state.h"

#import "base/test/ios/wait_util.h"
#import "testing/gtest/include/gtest/gtest.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_FAKE_APP_LAUNCHER_ABUSE_DETECTOR_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_FAKE_APP_LAUNCHER_ABUSE_DETECTOR_H_
#ifndef IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_FAKE_APP_LAUNCHER_ABUSE_DETECTOR_H_
#define IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_FAKE_APP_LAUNCHER_ABUSE_DETECTOR_H_

#import "ios/chrome/browser/app_launcher/app_launcher_abuse_detector.h"
#import "ios/chrome/browser/app_launcher/model/app_launcher_abuse_detector.h"

// An AppLauncherAbuseDetector for testing.
@interface FakeAppLauncherAbuseDetector : AppLauncherAbuseDetector
Expand All @@ -16,4 +16,4 @@

@end

#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_FAKE_APP_LAUNCHER_ABUSE_DETECTOR_H_
#endif // IOS_CHROME_BROWSER_APP_LAUNCHER_MODEL_FAKE_APP_LAUNCHER_ABUSE_DETECTOR_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/app_launcher/fake_app_launcher_abuse_detector.h"
#import "ios/chrome/browser/app_launcher/model/fake_app_launcher_abuse_detector.h"

@implementation FakeAppLauncherAbuseDetector

Expand Down
2 changes: 1 addition & 1 deletion ios/chrome/browser/main/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ source_set("main") {
deps = [
"//base",
"//components/breadcrumbs/core:status",
"//ios/chrome/browser/app_launcher",
"//ios/chrome/browser/app_launcher/model",
"//ios/chrome/browser/crash_report/breadcrumbs",
"//ios/chrome/browser/device_sharing",
"//ios/chrome/browser/follow:browser_agent",
Expand Down
2 changes: 1 addition & 1 deletion ios/chrome/browser/main/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ specific_include_rules = {
# TODO(crbug.com/1294160): Remove these dependencies.
"^browser_agent_util.mm": [
"+ios/chrome/browser/ui/start_surface/start_surface_recent_tab_browser_agent.h",
"+ios/chrome/browser/app_launcher/app_launcher_browser_agent.h",
"+ios/chrome/browser/app_launcher/model/app_launcher_browser_agent.h",
"+ios/chrome/browser/crash_report/breadcrumbs/breadcrumb_manager_browser_agent.h",
"+ios/chrome/browser/device_sharing/device_sharing_browser_agent.h",
"+ios/chrome/browser/follow/follow_browser_agent.h",
Expand Down

0 comments on commit 02a3527

Please sign in to comment.