Sleep command not working in Chromium.

70 views
Skip to first unread message

Jack Son

unread,
Nov 21, 2021, 4:12:18 PM11/21/21
to Chromium-dev
I'm trying to use the Sleep command in a function. (On Windows) But it doesn't work.

Like this:

// Copyright 2019 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 "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"

#include <cctype>

#include "components/ukm/content/source_url_recorder.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
++ #include <windows.h>

void LogClickToCallUKM(content::WebContents* web_contents,
                       SharingClickToCallEntryPoint entry_point,
                       bool has_devices,
                       bool has_apps,
                       SharingClickToCallSelection selection) {
  
  ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get();
  if (!ukm_recorder)
    return;
  
  ++ Sleep(300);
  ukm::SourceId source_id =
      ukm::GetSourceIdForWebContentsDocument(web_contents);
  if (source_id == ukm::kInvalidSourceId)
    return;

  ukm::builders::Sharing_ClickToCall(source_id)
      .SetEntryPoint(static_cast<int64_t>(entry_point))
      .SetHasDevices(has_devices)
      .SetHasApps(has_apps)
      .SetSelection(static_cast<int64_t>(selection))
      .Record(ukm_recorder);
}

Is there any other library I should add?
Thanks!

Bruce Dawson

unread,
Nov 22, 2021, 3:03:47 PM11/22/21
to Chromium-dev, Jack Son
You shouldn't use Sleep() directly in Chromium code - you should use base::PlatformThread::Sleep instead. There are lots of examples in the code.

As to why using Sleep() directly didn't work, I don't know. I've used it for temporary (not committed) code many times without problems. You'd have to give information about what sort of problems you hit rather than just "it doesn't work". One useful way to do that is to upload a work-in-progress CL using "git cl upload"

Reply all
Reply to author
Forward
0 new messages