-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[send-tab-to-self/ios] Share logic to check entry point state
No behavior is changed. Move it to //components so it can be called on iOS. Bug: 1264471 Change-Id: I1fc5cd31339f016057779737910c5ab54028cb67 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3637732 Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org> Reviewed-by: Sergio Collazos <sczs@chromium.org> Reviewed-by: Gabriel Charette <gab@chromium.org> Commit-Queue: Victor Vianna <victorvianna@google.com> Reviewed-by: Boris Sazonov <bsazonov@chromium.org> Cr-Commit-Position: refs/heads/main@{#1002610}
- Loading branch information
Victor Hugo Vianna Silva
authored and
Chromium LUCI CQ
committed
May 12, 2022
1 parent
c931620
commit f2271ab
Showing
14 changed files
with
336 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/send_tab_to_self/entry_point_display_reason.h" | ||
|
||
#include "components/prefs/pref_service.h" | ||
#include "components/send_tab_to_self/features.h" | ||
#include "components/send_tab_to_self/send_tab_to_self_model.h" | ||
#include "components/send_tab_to_self/send_tab_to_self_sync_service.h" | ||
#include "components/signin/public/base/signin_pref_names.h" | ||
#include "components/signin/public/identity_manager/account_info.h" | ||
#include "components/sync/driver/sync_service.h" | ||
#include "url/gurl.h" | ||
|
||
namespace send_tab_to_self { | ||
|
||
namespace { | ||
|
||
bool ShouldOfferSignin(syncer::SyncService* sync_service, | ||
PrefService* pref_service) { | ||
return pref_service->GetBoolean(prefs::kSigninAllowed) && sync_service && | ||
sync_service->GetAccountInfo().IsEmpty() && | ||
!sync_service->IsLocalSyncEnabled(); | ||
} | ||
|
||
} // namespace | ||
|
||
absl::optional<EntryPointDisplayReason> GetEntryPointDisplayReason( | ||
const GURL& url_to_share, | ||
syncer::SyncService* sync_service, | ||
SendTabToSelfSyncService* send_tab_to_self_sync_service, | ||
PrefService* pref_service) { | ||
if (!url_to_share.SchemeIsHTTPOrHTTPS()) | ||
return absl::nullopt; | ||
|
||
if (!send_tab_to_self_sync_service) { | ||
// Can happen in incognito or guest profile. | ||
return absl::nullopt; | ||
} | ||
|
||
if (ShouldOfferSignin(sync_service, pref_service) && | ||
base::FeatureList::IsEnabled(kSendTabToSelfSigninPromo)) { | ||
return EntryPointDisplayReason::kOfferSignIn; | ||
} | ||
|
||
SendTabToSelfModel* model = | ||
send_tab_to_self_sync_service->GetSendTabToSelfModel(); | ||
if (!model->IsReady()) | ||
return absl::nullopt; | ||
|
||
if (!model->HasValidTargetDevice()) { | ||
return base::FeatureList::IsEnabled(kSendTabToSelfSigninPromo) | ||
? absl::make_optional( | ||
EntryPointDisplayReason::kInformNoTargetDevice) | ||
: absl::nullopt; | ||
} | ||
|
||
return EntryPointDisplayReason::kOfferFeature; | ||
} | ||
|
||
} // namespace send_tab_to_self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_SEND_TAB_TO_SELF_ENTRY_POINT_DISPLAY_REASON_H_ | ||
#define COMPONENTS_SEND_TAB_TO_SELF_ENTRY_POINT_DISPLAY_REASON_H_ | ||
|
||
#include "third_party/abseil-cpp/absl/types/optional.h" | ||
|
||
class GURL; | ||
class PrefService; | ||
|
||
namespace syncer { | ||
class SyncService; | ||
} // namespace syncer | ||
|
||
namespace send_tab_to_self { | ||
|
||
class SendTabToSelfSyncService; | ||
|
||
enum class EntryPointDisplayReason { | ||
// The send-tab-to-self entry point should be shown because all the conditions | ||
// are met and the feature is ready to be used. | ||
kOfferFeature, | ||
// The user might be able to use send-tab-to-self if they sign in, so offer | ||
// that. "Might" because the list of target devices can't be known yet, it | ||
// could be empty (see below). | ||
kOfferSignIn, | ||
// All the conditions for send-tab-to-self are met, but there is no valid | ||
// target device. In that case the entry point should inform the user they | ||
// can enjoy the feature by signing in on other devices. | ||
kInformNoTargetDevice, | ||
}; | ||
|
||
// |sync_service| and |send_tab_to_self_sync_service| can be null. | ||
absl::optional<EntryPointDisplayReason> GetEntryPointDisplayReason( | ||
const GURL& url_to_share, | ||
syncer::SyncService* sync_service, | ||
SendTabToSelfSyncService* send_tab_to_self_sync_service, | ||
PrefService* pref_service); | ||
|
||
} // namespace send_tab_to_self | ||
|
||
#endif // COMPONENTS_SEND_TAB_TO_SELF_ENTRY_POINT_DISPLAY_REASON_H_ |
Oops, something went wrong.